The thread object uses the ThreadState property to indicate the thread status.
ThreadState is an enumeration type object with the flag feature. Therefore, bitmask must be used to determine the current state of the thread. as a special case, because the bit code of the Running state is 0, determine whether the thread is running in the following way: (myThread. threadState & (ThreadState. stopped | ThreadState. unstarted) = 0.
The enumerated members are as follows:
|
Member name |
Description |
|
Running |
The thread has been started, it is not blocked, and there is no pendingThreadAbortException. |
|
StopRequested |
The thread is being requested to stop. This is for internal use only. |
|
SuspendRequested |
The thread is being requested to suspend. |
|
Background |
The thread is being executed as a background thread, as opposed to a foreground thread. This state is controlled by setting theThread. IsBackground property. |
|
Unstarted |
The Thread. Start method has not been invoked on the thread. |
|
Stopped |
The thread has stopped. |
|
WaitSleepJoin |
The thread is blocked. this cocould be the result of calling Thread. sleep orThread. join, of requesting a lock-for example, by callingMonitor. enter orMonitor. wait-or of waiting on a thread synchronization object such asManualResetEvent. |
|
Sushortded |
The thread has been suincluded. |
|
AbortRequested |
The Thread. Abort method has been invoked on the thread, but the thread has not yet initialized ed the pendingSystem. Threading. ThreadAbortException that will attempt to terminate it. |
|
Aborted |
The thread state already des AbortRequested and the thread is now dead, but its state has not yet changed toStopped. |
The status transition diagram is as follows: