xin

关心
随笔 - 84, 评论 - 739, 引用 - 40

导航

关于

所有内容均属个人意见,没有任何担保或授权,以"现状"提供。“现状”到底是什么,我也不一定清楚。

标签

每月存档

最新留言

  • re: 2008 年 十大预测的总结 (只对了一半左右)
    我还记得一些: 1.人民币会继续升值(已经开贬了,正赶英超美ing……) 2.通胀加剧(是啊,越来越厉害了……连楼下自助洗衣房都在一月之内从3块一桶涨成4块一桶了) 3.SharePoint推广...
    by cy(匿名) on 2008/12/16 11:13:39
  • re: 同学们对《现代软件工程》课程的意见
    只看到tank和slobgraphics有可用的程序…… tank进了房间ready以后就只能在那里傻等…… slobgraphic感觉比windows自带的画图还难用…… 当然还少不了一些wo...
    by cy(匿名) on 2008/12/16 10:55:57
  • re: 人山人海人立方 http://renlifang.msra.cn
    "有奖竞猜 - 在人立方发布的第一天中,用户搜索的名词最多的是姚明,其次是刘翔,请问第三名是何许人也?" 嗯,陈冠希?
    by kaneboy(匿名) on 2008/8/7 16:29:04
  • re: 人山人海人立方 http://renlifang.msra.cn
    姚明能拿第一我才觉得奇怪呢,十强里面,东瀛女优国的爱情动作片巨星肯定占据大半江山。。。
    by cy(匿名) on 2008/8/4 13:04:00
  • re: 地图点儿莱唔点儿康的新功能 - 路况 和 短信
    用周边搜索,比如在西安的“西工大”周围搜“餐馆”,有一大堆返回结果,每个结果下方有个“发送到...”链接,单击后会有个下拉菜单,里面有个“免费短信”的选项。。。 地图搜索下貌似没找到这个featur...
    by cy(匿名) on 2008/7/14 13:36:13
  • fdffgsgg
    <a href="http://www.vgoldseller.com/runescape-c-599.html">runescape money</a> ...
    by cxb000(匿名) on 2008/3/26 10:33:44
  • re: 一目了然
    楼上的都答错了,是某某照门主角的关系网……
    by juqiang(匿名) on 2008/3/12 23:40:39
  • re: 重要但不紧急的事
    It's a test.
    by 开心就好(匿名) on 2008/3/9 15:58:02
  • 回复: 重要但不紧急的事
    收藏了。呵呵 <br>谢谢。 <br>新年快乐。
    by hello(匿名) on 2008/2/15 20:15:00
  • 回复: 一目了然
    最外面的点是什么,卫星链路吗
    by lee(匿名) on 2008/2/14 9:21:00
  • 回复: 重要但不紧急的事
    先盾看…… 有用时再细看
    by 91cn88(匿名) on 2008/2/13 23:53:00
  • 回复: 重要但不紧急的事
    嗯,不错,收藏,收藏,
    by xjb(匿名) on 2008/2/12 18:08:00
  • 回复: 重要但不紧急的事
    嗯,不错,收藏,收藏,
    by xjb(匿名) on 2008/2/12 18:08:00
  • 回复: 重要但不紧急的事
    EFFECTIVE C++ <br>N年前看过,基本忘光了... <br> <br>代码大全(第二版) <br>去年连滚带爬的看过... <br&...
    by kaneboy(匿名) on 2008/2/12 17:48:00
  • 重要但不紧急的事
    事儿真多。 有重要的事,有紧急的事,有紧急但不重要的事,也有重要但不紧急的事。(详细的论述参见 “超级高效人士的超级6+1个习惯”或者其他时间管理的书籍) 对于IT 行业的人来说,读书,是一件重要但不...
    by Joycode@Ab110.com(匿名) on 2008/2/12 13:32:00
  • 回复: 一目了然
    西瓜杀手 - 你真厉害。 <br> <br>排除了所有不可能的,剩下的选择,即使看上去非常不合情理,就是正确的答案。 <br>
    by xinz(匿名) on 2008/2/11 21:11:00
  • 回复: 一目了然
    有点晕乎,像是图的全连接
    by 沈胜衣(匿名) on 2008/2/11 6:38:00
  • 回复: 一目了然
    正确答案应该是关系距阵,应该是正确答案
    by netgod(匿名) on 2008/2/9 5:24:00
  • 回复: 一目了然
    正确答案是关系距阵
    by netgod(匿名) on 2008/2/9 5:23:00
  • 回复: 一目了然
    CCTV sucks! <br>连看个节目预告都看不了
    by tom(匿名) on 2008/2/8 3:52:00
  • 回复: 一目了然
    写得非常不错,思路不错, 顶一个,新年快乐……
    by 91cn44(匿名) on 2008/2/8 2:28:00
  • 回复: 一目了然
    我认为答案是d),原因如下: <br> <br>a) 某星系的结构图 <br>星系内各天体的分布不可能如此均匀,由万有引力可知,各星体直接都应该互相联系,与该图不符...
    by 西瓜杀手(匿名) on 2008/2/7 5:54:00
  • 回复: 一目了然
    这玩意儿天象不像啊。 <br>是什么东西呢。
    by 在线代理(匿名) on 2008/2/7 3:58:00
  • 回复: 一目了然
    电信早就做好流氓软件挺进广告业了 <br>CCTV做网络视频也绝对会成功,不过不需要网民参与而且质量也高 <br>
    by Hikey(匿名) on 2008/2/6 7:43:00
  • 回复: 一目了然
    一点儿也不&quot;一目了然&quot;...
    by VincentChen(匿名) on 2008/2/6 7:29:00

广告

 

一个简单的程序,用了 IAsyncResult 去实现异步操作。 MyWork() 内部通过delegate 调用了非托管的com 组件,但是,当这个程序在[STAThread] 状态下运行时,delegate 死活没有执行,程序进入死循环。

 

        public void Test1()

        {

            MyWork work = new MyWork();

            IAsyncResult ar = work.BeginWork();  //begin the async action

            while (!ar.IsCompleted)  //<--- this loop will run forever in an WinForm app.

            {

                //show progress

                Thread.Sleep(50);

            }

            if (ar.IsCompleted)

            {

                work.EndWork(); // get the result.

            }

        }

 

搞了半天,高手指点把Thread.Sleep() 换成 Thread.CurrentThread.Join(50) 就可以了!

虽然MSDN 对两个方法的解释是一样的:

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.

 

打印 | 张贴于 2004-08-22 14:31:00 | Tag:vs.net

留言反馈

#re: Thread.Sleep vs. Thread.CurrentThread.Join 编辑
楼上的说有啥区别
2006-02-19 09:45:00 | [匿名:sssdj舞曲]
#Heaven 要测试SQL Server 2005的镜像功能,居然要写个代码把Service给停掉! 编辑
.NET,Thread,Sleep,Join
2006-01-23 18:30:00 | [匿名:xport]
#re: Thread.Sleep vs. Thread.CurrentThread.Join 编辑
sleep的时候程序被挂起自然接受不到信息
2005-12-12 14:44:00 | [匿名:邱凯]
#re:Thread.Sleep vs. Thread.CurrentThread.Join 编辑
Thread.Sleep vs. Thread.CurrentThread.Joinooeess
2005-06-16 21:22:00 | [匿名:一氧化碳测定仪]
#re:Thread.Sleep vs. Thread.CurrentThread.Join 编辑
Thread.Sleep vs. Thread.CurrentThread.Joinooeess
2005-06-16 21:22:00 | [匿名:气味检测仪]
#re:Thread.Sleep vs. Thread.CurrentThread.Join 编辑
^_~,pretty good!csharpsseeoo
2005-05-18 20:14:00 | [匿名:电位滴定仪]
#re:Thread.Sleep vs. Thread.CurrentThread.Join 编辑
^_^,Pretty Good!
2005-04-10 20:23:00 | [匿名:多肽合成仪]
#re: Thread.Sleep vs. Thread.CurrentThread.Join 编辑
为什么不合成一个呢?
2004-08-23 14:58:00 | [匿名:风语者]
对不起,目前本随笔不允许发表新评论.

Powered by: Joycode.MVC引擎 0.5.2.0