The last few topics in this article are really just the few bits of reference information I dug up on .NET threads. This section describes the states of a thread. The Thread object in the .NET framework has a property called the ThreadState, which is one of the members of the following enumeration, which I pulled from the .NET documentation.
public enum ThreadState {
Running = 0,
SuspendRequested = 2,
Background = 4,
Unstarted = 8,
WaitSleepJoin = 32,
Suspended = 64,
AbortRequested = 128,
Aborted = 256
};
Unfortunately, I have been able to generate ThreadState's that are not in this enumeration. Specifically, the Stopped
ThreadState seems to be missing and is easy to generate. If you check the state of a thread that has run to completion, then the state is marked as Stopped. What I also found is that it is quite easy to generate dual states. You can be in the AbortRequested state and the WaitSleepJoin state. If you catch the
ThreadAbortException and then call Thread. Sleep, then the ThreadState will be "WaitSleepJoin, AbortRequested", a dual state. The same is true if you are sleeping when the Suspend instance method is called. Immediately after the call to the Suspend instance method, the ThreadState property reports "SuspendRequested, WaitSleepJoin", then quickly changes to "WaitSleepJoin, Suspended". I've encountered a few state diagrams that tried to depict the state transitions
of .NET threads. I must say that most are misleading or incomplete. The biggest problem is that most of the state diagrams did not attempt to account for dual states. My own attempt at the state diagram, I know, is still lacking but much further along then anything else I've seen (see Figure 1).
Figure 1: State Diagram 7
Comments