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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值