System.Threading.ThreadState Enum

public enum ThreadState

Base Types

Object
  ValueType
    Enum
      ThreadState

Assembly

mscorlib

Library

BCL

Summary

Specifies the execution states of a Thread.

Description

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 System.Threading.ThreadState.Stopped and System.Threading.ThreadState.Unstarted states.

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

ActionThreadState after Action
The thread is createdUnstarted
System.Threading.Thread.Start is invoked on the threadRunning
The thread calls System.Threading.Thread.Sleep(System.Int32)WaitSleepJoin
The thread calls System.Threading.Monitor.Wait(System.Object,System.Int32,System.Boolean) to wait on an objectWaitSleepJoin
The thread calls System.Threading.Thread.Join to wait for another thread to terminateWaitSleepJoin
The ThreadStart delegate methods finish executingStopped
Another thread requests the thread to System.Threading.Thread.Abort(System.Object)AbortRequested
The thread accepts a System.Threading.Thread.Abort(System.Object) requestAborted
In addition to the states noted above, there is also the System.Threading.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 System.Threading.Thread.ThreadState property, whose value is a combination of the ThreadState values. Once a thread has reached the System.Threading.ThreadState.Stopped state, it cannot change to any other state.

Attributes

FlagsAttribute

See Also

System.Threading Namespace

Members

ThreadState Fields

ThreadState.AbortRequested Field
ThreadState.Aborted Field
ThreadState.Background Field
ThreadState.Running Field
ThreadState.Stopped Field
ThreadState.Unstarted Field
ThreadState.WaitSleepJoin Field
ThreadState.value__ Field


ThreadState.AbortRequested Field

AbortRequested = 0x80;

Summary

The System.Threading.Thread.Abort(System.Object) method has been invoked on the thread, but the thread has not yet received the pending ThreadAbortException that will attempt to terminate it.

See Also

System.Threading.ThreadState Enum, System.Threading Namespace

ThreadState.Aborted Field

Aborted = 0x100;

Summary

The thread represented by an instance of Thread has terminated as a result of a call to System.Threading.Thread.Abort(System.Object). A thread in this state is also in the System.Threading.ThreadState.Stopped state.

See Also

System.Threading.ThreadState Enum, System.Threading Namespace

ThreadState.Background Field

Background = 0x4;

Summary

The thread represented by an instance of Thread is being executed as a background thread, as opposed to a foreground thread. [Note: This state is controlled by setting the System.Threading.Thread.IsBackground property.]

See Also

System.Threading.ThreadState Enum, System.Threading Namespace

ThreadState.Running Field

Running = 0x0;

Summary

The thread represented by an instance of Thread has been started and has not terminated.

To determine if a thread is running, check that its state does not include System.Threading.ThreadState.Unstarted and does not include System.Threading.ThreadState.Stopped.

See Also

System.Threading.ThreadState Enum, System.Threading Namespace

ThreadState.Stopped Field

Stopped = 0x10;

Summary

The thread represented by an instance of Thread has terminated.

See Also

System.Threading.ThreadState Enum, System.Threading Namespace

ThreadState.Unstarted Field

Unstarted = 0x8;

Summary

The System.Threading.Thread.Start method has not been invoked on the thread.

See Also

System.Threading.ThreadState Enum, System.Threading Namespace

ThreadState.WaitSleepJoin Field

WaitSleepJoin = 0x20;

Summary

The thread represented by an instance of Thread is blocked as a result of a call to System.Threading.Monitor.Wait(System.Object,System.Int32,System.Boolean), System.Threading.Thread.Sleep(System.Int32), or System.Threading.Thread.Join.

See Also

System.Threading.ThreadState Enum, System.Threading Namespace

ThreadState.value__ Field

value__;

See Also

System.Threading.ThreadState Enum, System.Threading Namespace