Thread.CurrentThread.Join()什么时候有意义? [英] When does Thread.CurrentThread.Join() make sense?
问题描述
调用Thread.CurrentThread.Join()的效果是什么,如果/何时调用它会有意义?
调用Thread.CurrentThread.Join()的效果是什么?执行当前线程,并有效地将其锁死。它会导致当前线程阻塞,直到当前线程完成,这将永远不会发生。
,如果/要调用它?
这样做是没有意义的。您不应该以这种方式调用此方法。
注意,我建议避免使用 Thread.Join
一般。使用新的任务
/ 任务< T>
类在许多方面都更好,因为您可以轻松地连接或者总是调用 Task.Wait()
,如果你真的需要阻止)。
What is the effect of calling Thread.CurrentThread.Join(), and if/when would it make sense to call it?
What is the effect of calling Thread.CurrentThread.Join()
You will block the execution of the current thread, and effectively dead lock it. It will cause the current thread to block until the current thread finishes, which will never happen.
, and if/when would it make sense to call it?
It really doesn't make sense to do this. You should never call this method in this manner.
On a side note, since you're using .NET 4, I would recommend avoiding using Thread.Join
in general. Using the new Task
/Task<T>
classes is far nicer in many ways, as you can easily attach continuations (or always call Task.Wait()
if you truly need to block).
这篇关于Thread.CurrentThread.Join()什么时候有意义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!