( 唱到:如果是这样,你不要悲伤~~~!!!)
用下面这个代码试试看看:
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.