Mono Class Library: System.Threading NamespaceSystem.Threading.ThreadState Enumeration |
|
System.Threading.ThreadState defines the set of possible execution states for threads. Once a thread is created, it is in one or more of these states until it terminates. Not all combinations of ThreadState values are valid; for example, a thread cannot be in both the ThreadState.Stopped and ThreadState.Unstarted states.
The following table shows the actions that cause a thread to change state.
Action ThreadState after Action The thread is created Unstarted Thread.Start is invoked on the thread Running The thread calls Thread.Sleep(int) WaitSleepJoin The thread calls Monitor.Wait(object, int, bool) to wait on an object WaitSleepJoin The thread calls Thread.Join to wait for another thread to terminate WaitSleepJoin The System.Threading.ThreadStart delegate methods finish executing Stopped Another thread requests the thread to Thread.Abort(object) AbortRequested The thread accepts a Thread.Abort(object) request Aborted In addition to the states noted above, there is also the ThreadState.Background state, which indicates whether the thread is running in the background or foreground.
The current state of a thread can be retrieved from the Thread.ThreadState property, whose value is a combination of the System.Threading.ThreadState values. Once a thread has reached the ThreadState.Stopped state, it cannot change to any other state.
[Edit]
Member Name Description Aborted The thread represented by an instance of System.Threading.Thread has terminated as a result of a call to Thread.Abort(object). A thread in this state is also in the ThreadState.Stopped state. [Edit] AbortRequested The Thread.Abort(object) method has been invoked on the thread, but the thread has not yet received the pending System.Threading.ThreadAbortException that will attempt to terminate it. [Edit] Background The thread represented by an instance of System.Threading.Thread is being executed as a background thread, as opposed to a foreground thread. Note: This state is controlled by setting the Thread.IsBackground property.[Edit]Running The thread represented by an instance of System.Threading.Thread has been started and has not terminated.
To determine if a thread is running, check that its state does not include ThreadState.Unstarted and does not include ThreadState.Stopped.
[Edit]Stopped The thread represented by an instance of System.Threading.Thread has terminated. [Edit] StopRequested Documentation for this section has not yet been entered. [Edit] Suspended Documentation for this section has not yet been entered. [Edit] SuspendRequested Documentation for this section has not yet been entered. [Edit] Unstarted The Thread.Start method has not been invoked on the thread. [Edit] WaitSleepJoin The thread represented by an instance of System.Threading.Thread is blocked as a result of a call to Monitor.Wait(object, int, bool), Thread.Sleep(int), or Thread.Join. [Edit]
Namespace: System.Threading
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0