BCL mscorlib [00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 ] 1.0.5000.0 2.0.0.0 4.0.0.0 System.Enum System.Flags System.Runtime.InteropServices.ComVisible(true)

The enumeration is of interest only in a few debugging scenarios. Your code should never use the thread state to synchronize the activities of threads.

defines a set of all possible execution states for threads. Once a thread is created, it is in at least one of the states until it terminates. Threads created within the common language runtime are initially in the Unstarted state, while external threads that come into the runtime are already in the Running state. An Unstarted thread is transitioned into the Running state by calling . Not all combinations of ThreadState values are valid; for example, a thread cannot be in both the Aborted and Unstarted states.

There are two thread state enumerations, and .

The following table shows the actions that cause a change of state.

Action

ThreadState

A thread is created within the common language runtime.

Unstarted

Another thread calls the method on the new thread, and the call returns.

The method does not return until the new thread has started running. There is no way to know at what point the new thread will start running, during the call to .

Running

The thread calls

WaitSleepJoin

The thread calls on another object.

WaitSleepJoin

The thread calls on another thread.

WaitSleepJoin

Another thread calls

Running

Another thread calls

SuspendRequested

The thread responds to a request.

Suspended

Another thread calls

Running

Another thread calls

AbortRequested

The thread responds to a request.

Stopped

A thread is terminated.

Stopped

In addition to the states noted above, there is also the Background state, which indicates whether the thread is running in the background or foreground.

A thread can be in more than one state at a given time. For example, if a thread is blocked on a call to , and another thread calls on the blocked thread, the blocked thread will be in both the WaitSleepJoin and the AbortRequested states at the same time. In this case, as soon as the thread returns from the call to or is interrupted, it will receive the to begin aborting.

The property of a thread provides the current state of a thread. Applications must use a bitmask to determine whether a thread is running. Since the value for Running is zero (0), test whether a thread is running by using C# code such as (myThread.ThreadState & (ThreadState.Stopped | ThreadState.Unstarted)) == 0 or Visual Basic code such as (myThread.ThreadState And (ThreadState.Stopped Or ThreadState.Unstarted)) = 0.

Specifies the execution states of a .

- Field
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Threading.ThreadState Aborted To be added.

  The thread state includes and the thread is now dead, but its state has not yet changed to .

  0
- Field
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Threading.ThreadState AbortRequested To be added.

  The method has been invoked on the thread, but the thread has not yet received the pending that will attempt to terminate it.

  0
- Field
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Threading.ThreadState Background To be added.

  The thread is being executed as a background thread, as opposed to a foreground thread. This state is controlled by setting the property.

  0
- Field
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Threading.ThreadState Running To be added.

  The thread has been started, it is not blocked, and there is no pending .

  0
- Field
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Threading.ThreadState Stopped To be added.

  The thread has stopped.

  0
- Field
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Threading.ThreadState StopRequested To be added.

  The thread is being requested to stop. This is for internal use only.

- Field
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Threading.ThreadState Suspended To be added.

  The thread has been suspended.

- Field
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Threading.ThreadState SuspendRequested To be added.

  The thread is being requested to suspend.

- Field
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Threading.ThreadState Unstarted To be added.

  The method has not been invoked on the thread.

  0
- Field
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Threading.ThreadState WaitSleepJoin To be added.

  The thread is blocked. This could be the result of calling or , of requesting a lock — for example, by calling or — or of waiting on a thread synchronization object such as .

  0
0