c# - Thread.Sleep 会影响 ThreadState 吗?

标签 c# multithreading

如果我创建并启动一个线程,在该线程中调用 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/

相关文章:

c# - C# 中是否有 List<T> 的方法,例如在 c++ 中为 vector<T> 调整大小

工作线程中的 C++ 未捕获异常

ios - EAGLContexts 共享 EAGLSharegroup 在子类化 GLKView 时给出错误

java - 迭代 HashMap 时出现 ConcurrentModificationException

c++ - 在 C++ 中使用 RAII 在线程包装类中 move 语义

c# - FileSystemWatcher 和最后一行文本文件

c# - 其中包含字符串操作的调试语句的最佳实践是什么?

c# - 使用 ? 时出现编译器错误。导致无法通过 PEVerify 的不良图像

c# - 在 Entity Framework linq 查询中将字符串转换为 int 并处理解析异常

java - 在不同步的情况下通过 100 个不同的线程递增静态变量,但最终结果为 100