System::Threading::Thread 类
内容
[
隐藏
]Thread class
Thread implementation. Objects of this class should only be allocated using System::MakeObject() function. Never create instance of this type on stack or using operator new, as it will result in runtime errors and/or assertion faults. Always wrap this class into System::SmartPtr pointer and use this pointer to pass it to functions as argument.
class Thread : public System::Object
方法
| 方法 | 描述 |
|---|---|
| Abort() | 中止线程。未实现。 |
| get_CurrentCulture() | 获取线程的区域性。 |
| static get_CurrentThread() | 获取描述当前线程的对象。 |
| get_CurrentUICulture() | 获取线程使用的用户界面区域性。 |
| get_IsAlive() | 检查线程是否仍在运行。 |
| get_IsBackground() | 检查线程是否为后台线程。 |
| get_IsThreadPoolThread() | 检查线程是否由线程池拥有。 |
| get_ManagedThreadId() const | 获取线程标识符。可以从操作系统获取,但如果操作系统的线程标识符超出 int 限制,线程的 ID 可能会冲突。 |
| get_Name() | 获取线程名称。 |
| get_ThreadState() | 获取线程状态。 |
| static GetCurrentThreadId() | 获取当前线程的标识符。 |
| GetHashCode() const override | |
| Interrupt() | 中断线程。未实现。 |
| Join() | 加入受管线程。如有需要,执行无限等待。 |
| Join(int) | 加入受管线程。执行有限等待。 |
| Join(TimeSpan) | 加入受管线程。执行有限等待。 |
| static MemoryBarrier() | 同步内存访问。 |
| operator=(const Thread&) | 从其他线程复制 TLS 数据。 |
| set_CurrentCulture(const SharedPtr<Globalization::CultureInfo>&) | 设置线程区域性。 |
| set_CurrentUICulture(const SharedPtr<Globalization::CultureInfo>&) | 设置线程使用的用户界面区域性。 |
| set_IsBackground(bool) | 将线程设置为后台或前台。 |
| set_Name(const System::String&) | 设置线程名称。 |
| static Sleep(int) | 在指定的超时时间内停止当前线程。 |
| static Sleep(TimeSpan) | 在指定的超时时间内停止当前线程。 |
| static SpinWait(int) | 等待特定次数的循环迭代。 |
| Start() | 使用空参数对象启动线程。 |
| Start(const System::SharedPtr<System::Object>&) | 启动线程。 |
| Thread() | 构造函数。 |
| Thread(ThreadStart) | 构造函数。 |
| Thread(ParameterizedThreadStart) | 构造函数。 |
| Thread(Thread&) | 拷贝构造函数。 |
| static Yield() | 产生线程。 |
| virtual ~Thread() | 析构函数。 |
备注
#include "system/threading/thread.h"
#include "system/smart_ptr.h"
int main()
{
auto thread = System::MakeObject<System::Threading::Thread>([]()
{
std::cout << "Child thread ID: " << System::Threading::Thread::GetCurrentThreadId() << std::endl;
System::Threading::Thread::Sleep(200);
});
std::cout << "Main thread ID: " << System::Threading::Thread::GetCurrentThreadId() << std::endl;
thread->Start();
thread->Join();
return 0;
}
/*
This code example produces the following output:
Main thread ID: 2
Child thread ID: 1
*/
另见
- Class Object
- Namespace System::Threading
- Library Aspose.Font for C++