You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: xml/System.Threading/ThreadState.xml
+13-12Lines changed: 13 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -42,12 +42,16 @@
42
42
<formattype="text/markdown"><![CDATA[
43
43
44
44
## Remarks
45
-
The <xref:System.Threading.ThreadState> enumeration is of interest only in a few debugging scenarios. Your code should never use the thread state to synchronize the activities of threads.
45
+
The `ThreadState` enumeration defines a set of all possible execution states for threads. It's of interest only in a few debugging scenarios. Your code should never use the thread state to synchronize the activities of threads.
46
46
47
-
<xref:System.Threading.ThreadState> 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 <xref:System.Threading.Thread.Start%2A>. Not all combinations of `ThreadState` values are valid; for example, a thread cannot be in both the `Aborted` and `Unstarted` states.
47
+
Once a thread is created, it's in at least one of the states until it terminates. Threads created within the common language runtime are initially in the <xref:System.Threading.ThreadState.Unstarted> state, while external, or unmanaged, threads that come into the runtime are already in the <xref:System.Threading.ThreadState.Running> state. A thread is transitioned from the <xref:System.Threading.ThreadState.Unstarted> state into the <xref:System.Threading.ThreadState.Running> state by calling <xref:System.Threading.Thread.Start%2A?displayProperty=nameWithType>. Once a thread leaves the <xref:System.Threading.ThreadState.Unstarted> state as the result of a call to <xref:System.Threading.Thread.Start%2A>, it can never return to the <xref:System.Threading.ThreadState.Unstarted> state.
48
+
49
+
A thread can be in more than one state at a given time. For example, if a thread is blocked on a call to <xref:System.Threading.Monitor.Wait%2A?displayProperty=nameWithType>, and another thread calls <xref:System.Threading.Thread.Abort%2A?displayProperty=nameWithType> on the blocked thread, the blocked thread will be in both the <xref:System.Threading.ThreadState.WaitSleepJoin> and <xref:System.Threading.ThreadState.AbortRequested> states at the same time. In this case, as soon as the thread returns from the call to <xref:System.Threading.Monitor.Wait%2A?displayProperty=nameWithType> or is interrupted, it will receive the <xref:System.Threading.ThreadAbortException> to begin aborting. Not all combinations of `ThreadState` values are valid; for example, a thread cannot be in both the <xref:System.Threading.ThreadState.Aborted> and <xref:System.Threading.ThreadState.Unstarted> states.
50
+
51
+
A thread can never leave the <xref:System.Threading.ThreadState.Stopped> state.
48
52
49
53
> [!IMPORTANT]
50
-
> There are two thread state enumerations: <xref:System.Threading.ThreadState?displayProperty=nameWithType> and <xref:System.Diagnostics.ThreadState?displayProperty=nameWithType>.
54
+
> There are two thread state enumerations: <xref:System.Threading.ThreadState?displayProperty=nameWithType> and <xref:System.Diagnostics.ThreadState?displayProperty=nameWithType>.
51
55
52
56
The following table shows the actions that cause a change of state.
53
57
@@ -56,20 +60,18 @@
56
60
|A thread is created within the common language runtime.|<xref:System.Threading.ThreadState.Unstarted>|
57
61
|Another thread calls the <xref:System.Threading.Thread.Start%2A?displayProperty=nameWithType> method on the new thread, and the call returns.<br /><br /> The <xref:System.Threading.Thread.Start%2A> 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 <xref:System.Threading.Thread.Start%2A>.|<xref:System.Threading.ThreadState.Running>|
|The thread calls <xref:System.Threading.Monitor.Wait%2A> on another object.|<xref:System.Threading.ThreadState.WaitSleepJoin>|
63
+
|The thread calls <xref:System.Threading.Monitor.Wait%2A?displayProperty=nameWithType> on another object.|<xref:System.Threading.ThreadState.WaitSleepJoin>|
60
64
|The thread calls <xref:System.Threading.Thread.Join%2A> on another thread.|<xref:System.Threading.ThreadState.WaitSleepJoin>|
|The thread responds to a <xref:System.Threading.Thread.Abort%2A> request.|<xref:System.Threading.ThreadState.Stopped>|
67
-
|A thread is terminated.|Stopped|
68
-
69
-
In addition to the states noted above, there is also the <xref:System.Threading.ThreadState.Background> state, which indicates whether the thread is running in the background or foreground.
70
-
71
-
A thread can be in more than one state at a given time. For example, if a thread is blocked on a call to <xref:System.Threading.Monitor.Wait%2A>, and another thread calls <xref:System.Threading.Thread.Abort%2A> on the blocked thread, the blocked thread will be in both the <xref:System.Threading.ThreadState.WaitSleepJoin> and the <xref:System.Threading.ThreadState.AbortRequested> states at the same time. In this case, as soon as the thread returns from the call to <xref:System.Threading.Monitor.Wait%2A> or is interrupted, it will receive the <xref:System.Threading.ThreadAbortException> to begin aborting.
70
+
|The thread responds to an <xref:System.Threading.Thread.Abort%2A> request.|<xref:System.Threading.ThreadState.Stopped>|
71
+
|A thread is terminated.|<xref:System.Threading.ThreadState.Stopped>|
72
72
73
+
In addition to the states noted above, there is also the <xref:System.Threading.ThreadState.Background> state, which indicates whether the thread is running in the background or foreground. For more information, see [Foreground and Background Threads](~/docs/standard/threading/foreground-and-background-threads.md).
74
+
73
75
The <xref:System.Threading.Thread.ThreadState%2A?displayProperty=nameWithType> property of a thread provides the current state of a thread. Applications must use a bit mask to determine whether a thread is running. Since the value for <xref:System.Threading.ThreadState.Running> is zero (0), test whether a thread is running by the following code:
0 commit comments