MSDN说通过Join,标准COM和SendMessage抽取 继续,但这对于典型的Windows 表单或Windows服务的实践意味着什么应用程序?? 有人说你应该总是使用后者。 但是如果你把这些命令中的任何一个放到简单的Windows Forms应用程序中 - ,例如在按钮事件处理程序上 - 应用程序无响应,因为 10秒。那么有什么区别(如果有的话?) 谢谢 JoeDoes anyone know the difference, in practical terms, betweenThread.Sleep (10000) and Thread.CurrentThread.Join (10000)??The MSDN says that with Join, standard COM and SendMessage pumpingcontinues, but what does this mean in practice for a typical WindowsForms or Windows Service application??Some people say you should always use the latter.But if you put either of these commands into simple Windows Forms app -eg on a button event handler - the application becomes unresponsive for10 seconds. So what''s the difference (if any?)ThanksJoe推荐答案乔, 根据我自己的经验,Thread.Join和之间的唯一区别 Thread.Sleep是如何线程的实际上等待。 Thread.Sleep()理论上应该不会阻止你的应用程序响应 其他线程,即主线程。在哪里作为Thread.Join()。 Thread.Join()将确保一个线程已经终止,理论上阻止调用线程无限期地支持,直到调用线程终止。 问候 Scott Blood C#开发者 乔 <乔******* @ gmail.com>在消息中写道 news:11 ********************* @ e56g2000cwe.googlegro ups.com ...Joe,In my own experience the only difference between Thread.Join andThread.Sleep is how the thread actually waits.Thread.Sleep() in theory should no stop your application from responding toother Threads, i.e. the main one. Where as Thread.Join().Thread.Join() will ensure that a thread has terminated, in theory, blockingthe call thread indefinatly, until the calling thread terminates.RegardsScott BloodC# Developer"Joe" <jo*******@gmail.com> wrote in messagenews:11*********************@e56g2000cwe.googlegro ups.com...有没有人知道实际上它们之间的区别 Thread.Sleep(10000)和Thread.CurrentThread.Join(10000)?? MSDN说使用Join,标准COM和SendMessage抽取继续,但这对于典型的Windows Forms或Windows Service应用程序的实践意味着什么? 有人说你应该总是使用后者。 但是如果你将这些命令中的任何一个放入简单的Windows窗体应用程序中 - 例如在按钮事件处理程序上 - 应用程序就会在10秒钟内无响应。那么有什么区别(如果有的话?) 谢谢 Joe Does anyone know the difference, in practical terms, between Thread.Sleep (10000) and Thread.CurrentThread.Join (10000)?? The MSDN says that with Join, standard COM and SendMessage pumping continues, but what does this mean in practice for a typical Windows Forms or Windows Service application?? Some people say you should always use the latter. But if you put either of these commands into simple Windows Forms app - eg on a button event handler - the application becomes unresponsive for 10 seconds. So what''s the difference (if any?) Thanks Joe TMK,你只有1个UI线程,所以如果你使用其中任何一个,你的UI线程将会阻止阻塞(即不会出队消息)。在UI线程上通过BeginInvoke 发布的其他线程可能能够发布到队列,但UI线程仍将被阻止。我永远不会睡觉或加入UI线程,除非 你准备等待,这是必需的行为(并提出等待 游标)。 /> - William Stacey [MVP] " Joe" <乔******* @ gmail.com>在消息中写道 新闻:11 ********************* @ e56g2000cwe.googlegro ups.com ... |实际上,有没有人知道这两者之间的区别 | | Thread.Sleep(10000)和Thread.CurrentThread.Join(10000)?? | | MSDN说通过Join,标准COM和SendMessage抽取 |继续,但这对于典型的Windows实际意味着什么? |表格或Windows服务应用程序?? | |有人说你应该总是使用后者。 | |但是,如果您将这些命令中的任何一个放入简单的Windows窗体应用程序中 - |例如,在按钮事件处理程序上 - 应用程序对 |没有响应10秒那有什么区别(如果有的话) | |谢谢 | Joe |TMK, you only have 1 UI thread, so if you use either, your UI thread willblock (i.e. not dequeue message). Other threads that post via BeginInvokeon the UI thread may be able to post to the queue, but the UI thread willstill be blocked. I would not ever sleep or join in the UI thread, unlessyour prepard to wait and that is the required behavior (and put up the waitcursor).--William Stacey [MVP]"Joe" <jo*******@gmail.com> wrote in messagenews:11*********************@e56g2000cwe.googlegro ups.com...| Does anyone know the difference, in practical terms, between|| Thread.Sleep (10000) and Thread.CurrentThread.Join (10000)??|| The MSDN says that with Join, standard COM and SendMessage pumping| continues, but what does this mean in practice for a typical Windows| Forms or Windows Service application??|| Some people say you should always use the latter.|| But if you put either of these commands into simple Windows Forms app -| eg on a button event handler - the application becomes unresponsive for| 10 seconds. So what''s the difference (if any?)|| Thanks| Joe|我写了一个简单的STAThread Windows Forms测试应用程序,就像你一样 描述,从另一个线程通过BeginInvoke队列调用队列直到 主线程上的Sleep或Join结束。 尽管如此,这种行为是否相同Thread.Sleep(x)或 使用Thread.CurrentThread.Join(x)。 因此它仍然存在问题,实际上是否存在(非学术性) 两者之间的差异?在说Thread.Sleep (x)是错误的时候会误导人们你应该使用Thread.CurrentThread.Join(x)吗? JoeI''ve written a simple STAThread Windows Forms test app, and just as youdescribe, calls made from another thread via BeginInvoke queue up untilthe Sleep or Join on the main thread is over.Nonetheless, this behavior is identical whether Thread.Sleep (x) orThread.CurrentThread.Join (x) is used.So it still leaves the question, is there in fact any (non-academic)difference between the two? Are people misled when saying Thread.Sleep(x) is wrong and you should use Thread.CurrentThread.Join (x) instead?Joe 这篇关于Thread.Sleep vs Thread.Join的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!