Specifies the execution state of a thread.
public enum ThreadState
Member name | Value | Description |
---|---|---|
Running | 0 | The thread is running and executing code. |
Paused | 1 | The thread is paused. This state is usually not returned by the Thread.ThreadState property. |
Stopped | 2 | The thread has terminated. |
WaitSleepJoin | 4 | The thread is suspended because it is waiting, sleeping, or has joined another thread. |
Suspended | 8 | The thread is suspended. |
AbortRequested | 16 | A request to abort the thread has been made. |
Background | 32 | The thread is a background thread. |
Unstarted | 64 | The thread has not been started yet. |
StoppedRequested | 128 | Indicates that the thread has terminated. This value is obsolete. Use Stopped instead. |
StopRequested | 256 | A request to stop the thread has been made. |
SuspendedRequested | 512 | A request to suspend the thread has been made. |
The ThreadState
enumeration represents the possible states of a thread.
You can combine ThreadState
values using the bitwise OR operator (|
) to determine the current state of a thread. For example, a thread can be both Running
and Suspended
if it is a background thread that has been suspended.
// Get the current thread's state Thread currentThread = Thread.CurrentThread; ThreadState state = currentThread.ThreadState; // Check if the thread is running if (state & ThreadState.Running == ThreadState.Running) { Console.WriteLine("The thread is currently running."); } // Check if the thread has been suspended if (state & ThreadState.Suspended != 0) { Console.WriteLine("The thread is suspended."); }