Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有人可以向我解释 Thread.Sleep(period) 和 Thread.CurrentThread.Join(period) 之间到底有什么区别?
好吧,Thread.Sleep阻塞线程一段特定的时间,同时Thread.Join阻塞它直到目标线程终止。
Thread.Sleep
Thread.Join
考虑Thread.CurrentThread到它在暂停时不会被终止(即使它在外部终止也没有什么区别,因为它已经死了),最终结果将是相同的。然而,使用Join是令人困惑的,而Sleep很明显。决定使用哪一个是没有争议的。
Thread.CurrentThread
Join
Sleep