Heaven 要测试SQL Server 2005的镜像功能,居然要写个代码把程序停止响应!

王朝c#·作者佚名  2006-12-17
窄屏简体版  字體: |||超大  

Heaven 要测试SQL Server 2005的镜像功能,居然要写个代码把程序停止响应!

Heaven 要测试SQL Server 2005的镜像功能,居然要写个代码把程序停止响应! 真是BT啊...也不知道如何来做,难道是把所有的线程都Hang住么?

( 唱到:如果是这样,你不要悲伤~~~!!!)

用下面这个代码试试看看:

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

Blocks the current thread for the specified number of milliseconds.

但是它们有细微而重要的区别,根据这个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.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航