如果我创建并启动一个线程,在该线程中调用 Thread.Sleep(x) 会如何影响 ThreadState(如果有的话)?
谢谢!
最佳答案
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 Start. Not all combinations of ThreadState values are valid; for example, a thread cannot be in both the Aborted and Unstarted states.
Important: Thread state is only of interest in a few debugging scenarios. Your code should never use thread state to synchronize the activities of threads.
ThreadState:WaitSleepJoin:线程因调用 Wait、Sleep 或 Join 而被阻塞。
来自 here .
关于c# - Thread.Sleep 会影响 ThreadState 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/970497/