how to infer the current state of a thread in C #
sinom in C #. Thread Object thread uses the ThreadState property to indicate the thread state. Itis an enumerated type object with the Flags attribute.
ThreadState defines a set of all possible execution states for a thread. Once the thread is created. It is at least in one of the states . Until terminated.
Threads created in the common language execution are initially in the unstarted state. The external thread that enters execution is already in the running state.
The unstarted thread can be converted to the running state by calling start. Not all combinations of threadstate values are valid; For example, threads cannot be in aborted and unstarted states at the same time.Therefore, it is inferred that the current state of the thread must be inferred using the bitmask bitwise operation and cannot be inferred directly using equality.
define threadstate such as the following:
1. Infer if the thread is in a canceled state A. Incorrect inference (mythread.threadstate = = threadstate.abortrequested) B. Correct inference(myThread.ThreadState & threadstate.abortrequested)! = 0
2. Infer whether the thread is in the execution state This one is a little special. Because threadstate.running equals 0. The & operation is not possible, so inference can be made using the following method: (mythread.threadstate = = ThreadState. Running)
How to infer the current state of a thread in C #