RLib  5.7
RLib - an opensource, lightweight and multi-platform framework for cpp programming
System::Threading::Thread Class Reference

Creates and controls a thread, sets its priority, and gets its status How to: Set a Thread Name in Native Code https://msdn.microsoft.com/en-us//library/xcb2z8hs.aspx More...

Public Member Functions

 Thread (HANDLE, DWORD, BOOL IsRunning)
 使用指定的线程句柄及线程ID(允许为0)初始化新的Thread类 自动接管该句柄的所有工作, 默认该线程正在运行 More...
 
 Thread (const Runnable &)
 初始化 Thread 类的新实例 More...
 
 Thread (Runnable::StdParameterizedThreadStart, LPVOID lpParameter)
 初始化 Thread 类的新实例,并允许传参数给线程 More...
 
 Thread (Runnable::StdThreadStart)
 初始化 Thread 类的新实例 More...
 
 Thread (Runnable::CppParameterizedThreadStart, LPVOID lpParameter)
 初始化 Thread 类的新实例,并允许传参数给线程 More...
 
 Thread (Runnable::CppThreadStart)
 初始化 Thread 类的新实例 More...
 
 ~Thread ()
 释放内存并关闭线程对象 如果在线程过程中销毁线程对象本身, 则必须调用ExitThread以退出线程 More...
 
void SetParameter (LPVOID lpParameter)
 设置一个值,该值表示线程执行时使用的参数 方法必须在 Start 方法执行前被调用 More...
 
 operator HANDLE ()
 获取线程对象句柄 More...
 
const DWORD GetThreadId () const
 获取线程ID, 失败返回0 More...
 
 RLIB_PROPERTY_GET (DWORD ThreadId, GetThreadId)
 获取线程Id More...
 
void SetThreadName (LPCSTR)
 设置线程名称, 仅在调试器中有效 More...
 
 RLIB_PROPERTY_SET (LPCSTR ThreadName, SetThreadName)
 设置线程名称, 仅在调试器中有效 More...
 
ThreadPriority GetPriority () const
 获取一个值,该值指示线程的调度优先级 失败返回 ErrorPriority More...
 
bool SetPriority (ThreadPriority newPriority)
 设置一个值,该值指示线程的调度优先级 LowestPriority < newPriority <= HighestPriority More...
 
 RLIB_PROPERTY_GET_SET (ThreadPriority Priority, GetPriority, SetPriority)
 获取或设置一个值,该值指示线程的调度优先级 More...
 
RLIB_INLINE ThreadSetBackground (bool bIsBackground=true)
 设置一个值,该值指示某个线程是否为后台线程 More...
 
bool GetIsAlive () const
 获取一个值,该值指示当前线程的执行状态 如果此线程已启动并且尚未正常终止或中止,则为 true;否则为 false More...
 
 RLIB_PROPERTY_GET (bool IsAlive, GetIsAlive)
 如果此线程已启动并且尚未正常终止或中止,则为 true;否则为 false More...
 
ThreadState GetState () const
 获取一个值,该值指示当前线程的状态 More...
 
 RLIB_PROPERTY_GET (ThreadState State, GetState)
 获取一个值,该值指示当前线程的状态 More...
 
bool Start ()
 导致操作系统将当前实例的状态更改为 ThreadState::Running More...
 
bool Alert ()
 唤醒线程 More...
 
bool Resume ()
 已过时.继续已挂起的线程 More...
 
bool Suspend ()
 已过时.挂起线程,或者如果线程已挂起,则不起作用 More...
 
bool Abort (long exitstatus=-1)
 已过时.在调用此方法以开始中止此线程, 调用此方法通常会中止线程 More...
 
WaitStatus Wait (DWORD millisecondsTimeout=INFINITE)
 在当前线程上执行等待操作, 调用 Start() 后立即调用 Wait() 可能不起作用(线程状态未更新) More...
 
bool Close ()
 关闭线程对象 More...
 
ThreadException * GetLastException ()
 获取Thread发生的异常信息 More...
 

Static Public Member Functions

static ThreadGetCurrentThread ()
 获取当前正在运行的线程 More...
 
static void ExitThread (DWORD code=0)
 退出当前线程并释放线程内存 More...
 
static WaitStatus Sleep (DWORD dwMilliseconds, bool bAlertable=true)
 将当前线程挂起指定的时间并指定是否允许唤醒线程 More...
 
static bool AlertThread (HANDLE hThread)
 唤醒指定线程 More...
 
static ULONG AlertResumeThread (HANDLE hThread)
 Difference between AlertResumeThread and Thread.Resume it's the first one sets Thread LPVOID to alerted state (so before thread will continue execution, all APC will be executed). More...
 
static void SetThreadName (DWORD threadId, LPCSTR name)
 设置线程名称, 仅在调试器中有效 More...
 

Public Attributes

 RLIB_DECLARE_DYNCREATE
 
bool IsBackground
 获取或设置一个值,该值指示某个线程是否为后台线程 如果该属性为true, 则线程结束时将自动销毁 Thread 实例, 这意味着无须 手动释放 Thread 实例. More...
 
bool IsSuppressChangeState
 获取或设置一个值,该值指示是否禁止在线程结束时更新为 ThreadState::Stoped 状态 如果该值被设置为 true, 则必须调用 ExitThread 方法结束线程 默认值为 false More...
 

Detailed Description

Creates and controls a thread, sets its priority, and gets its status How to: Set a Thread Name in Native Code https://msdn.microsoft.com/en-us//library/xcb2z8hs.aspx

Constructor & Destructor Documentation

Thread::Thread ( HANDLE  hThread,
DWORD  ThreadId,
BOOL  IsRunning 
)

使用指定的线程句柄及线程ID(允许为0)初始化新的Thread类 自动接管该句柄的所有工作, 默认该线程正在运行

Thread::Thread ( const Runnable run)

初始化 Thread 类的新实例

Thread::Thread ( Runnable::StdParameterizedThreadStart  lpRoutine,
LPVOID  lpParameter 
)

初始化 Thread 类的新实例,并允许传参数给线程

Thread::Thread ( Runnable::StdThreadStart  lpRoutine)

初始化 Thread 类的新实例

Thread::Thread ( Runnable::CppParameterizedThreadStart  lpRoutine,
LPVOID  lpParameter 
)

初始化 Thread 类的新实例,并允许传参数给线程

Thread::Thread ( Runnable::CppThreadStart  lpRoutine)

初始化 Thread 类的新实例

Thread::~Thread ( )

释放内存并关闭线程对象 如果在线程过程中销毁线程对象本身, 则必须调用ExitThread以退出线程

Member Function Documentation

bool Thread::Abort ( long  exitstatus = -1)

已过时.在调用此方法以开始中止此线程, 调用此方法通常会中止线程

bool Thread::Alert ( )

唤醒线程

ULONG Thread::AlertResumeThread ( HANDLE  hThread)
static

Difference between AlertResumeThread and Thread.Resume it's the first one sets Thread LPVOID to alerted state (so before thread will continue execution, all APC will be executed).

Returns
Returns number of suspend request for thread ThreadHandle before call AlertResumeThread. If this number is 0, thread will continue execution.
bool Thread::AlertThread ( HANDLE  hThread)
static

唤醒指定线程

bool Thread::Close ( )

关闭线程对象

void Thread::ExitThread ( DWORD  code = 0)
static

退出当前线程并释放线程内存

Thread * Thread::GetCurrentThread ( )
static

获取当前正在运行的线程

bool Thread::GetIsAlive ( ) const

获取一个值,该值指示当前线程的执行状态 如果此线程已启动并且尚未正常终止或中止,则为 true;否则为 false

ThreadException * Thread::GetLastException ( )

获取Thread发生的异常信息

ThreadPriority Thread::GetPriority ( ) const

获取一个值,该值指示线程的调度优先级 失败返回 ErrorPriority

ThreadState Thread::GetState ( ) const

获取一个值,该值指示当前线程的状态

const DWORD Thread::GetThreadId ( ) const

获取线程ID, 失败返回0

Thread::operator HANDLE ( )

获取线程对象句柄

bool Thread::Resume ( )

已过时.继续已挂起的线程

System::Threading::Thread::RLIB_PROPERTY_GET ( DWORD  ThreadId,
GetThreadId   
)

获取线程Id

System::Threading::Thread::RLIB_PROPERTY_GET ( bool  IsAlive,
GetIsAlive   
)

如果此线程已启动并且尚未正常终止或中止,则为 true;否则为 false

System::Threading::Thread::RLIB_PROPERTY_GET ( ThreadState  State,
GetState   
)

获取一个值,该值指示当前线程的状态

System::Threading::Thread::RLIB_PROPERTY_GET_SET ( ThreadPriority  Priority,
GetPriority  ,
SetPriority   
)

获取或设置一个值,该值指示线程的调度优先级

System::Threading::Thread::RLIB_PROPERTY_SET ( LPCSTR  ThreadName,
SetThreadName   
)

设置线程名称, 仅在调试器中有效

Warning
the caller must handle EXCEPTION_MS_VC(0x406D1388)
RLIB_INLINE Thread* System::Threading::Thread::SetBackground ( bool  bIsBackground = true)
inline

设置一个值,该值指示某个线程是否为后台线程

See also
IsBackground
void Thread::SetParameter ( LPVOID  lpParameter)

设置一个值,该值表示线程执行时使用的参数 方法必须在 Start 方法执行前被调用

bool Thread::SetPriority ( ThreadPriority  newPriority)

设置一个值,该值指示线程的调度优先级 LowestPriority < newPriority <= HighestPriority

void Thread::SetThreadName ( LPCSTR  name)

设置线程名称, 仅在调试器中有效

Warning
the caller must handle EXCEPTION_MS_VC(0x406D1388)
void Thread::SetThreadName ( DWORD  threadId,
LPCSTR  name 
)
static

设置线程名称, 仅在调试器中有效

Warning
the caller must handle EXCEPTION_MS_VC(0x406D1388)
WaitStatus Thread::Sleep ( DWORD  dwMilliseconds,
bool  bAlertable = true 
)
static

将当前线程挂起指定的时间并指定是否允许唤醒线程

Returns
WAIT_TIMEOUTED if the specified time interval expired. WAIT_ALERTED if the function returned due to one or more I/O completion callback functions. This can happen only if bAlertable is true, and if the thread that called the WAIT_ALERTED function is the same thread that called the extended I/O function.
bool Thread::Start ( )

导致操作系统将当前实例的状态更改为 ThreadState::Running

bool Thread::Suspend ( )

已过时.挂起线程,或者如果线程已挂起,则不起作用

WaitStatus Thread::Wait ( DWORD  millisecondsTimeout = INFINITE)

在当前线程上执行等待操作, 调用 Start() 后立即调用 Wait() 可能不起作用(线程状态未更新)

Member Data Documentation

bool System::Threading::Thread::IsBackground

获取或设置一个值,该值指示某个线程是否为后台线程 如果该属性为true, 则线程结束时将自动销毁 Thread 实例, 这意味着无须 手动释放 Thread 实例.

bool System::Threading::Thread::IsSuppressChangeState

获取或设置一个值,该值指示是否禁止在线程结束时更新为 ThreadState::Stoped 状态 如果该值被设置为 true, 则必须调用 ExitThread 方法结束线程 默认值为 false


The documentation for this class was generated from the following files: