( 唱到:如果是这样,你不要悲伤~~~!!!)
用下面这个代码试试看看:
|
1 using System; 2 using System.Threading; 3 4 public class Test { 5 public static void Main(String[] args) { 6 //Thread.CurrentThread.Sleep(500); 7 Thread.CurrentThread.Join(5000000); 8 Console.WriteLine("874 Heaven * 100"); 9 } 10 } |
原因如下 (摘自 http://blog.joycode.com/xinz/archive/2004/08/22/31313.aspx ):
| Thread.Join Blocks the calling thread until a thread terminates or the specified time elapses. |
| Thread.Sleep |
但是它们有细微而重要的区别,根据这个BLOG :
Thread.Sleep is a little unusual. We can take control of threads that are inside this service. But, following the tradition of Sleep on the underlying Windows operating system, we perform no pumping.
If you need to Sleep on an STA thread, but you want to perform the standard COM and SendMessage pumping, consider Thread.CurrentThread.Join(timeout) as a replacement.
本文探讨了在.NET中Thread.Join与Thread.Sleep方法的不同之处。Thread.Join方法会阻塞调用线程直到被加入的线程终止或指定的时间间隔到期。而Thread.Sleep则会将当前线程阻塞指定的毫秒数。两者之间的主要区别在于Thread.Sleep不进行窗口消息泵送,如果需要在特定线程上睡眠并执行标准的COM和窗口消息泵送,则建议使用Thread.CurrentThread.Join(timeout)。
7105

被折叠的 条评论
为什么被折叠?



