Thread.Sleep如何暂停工作线程? [英] How Thread.Sleep pause worker thread?

查看:174
本文介绍了Thread.Sleep如何暂停工作线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Thread t = new Thread(Method1);
t.Start(); 
Thread.Sleep(2000); 
t.Join();
Thread t1 = new Thread(Method2); 
t1.Start(); 
Thread.Sleep(2000); 
t1.Join();
Thread t2 = new Thread(Method3); 
t2.Start();
How Thread.Sleep()  makes each thread wait? How is it associated with each thread?

推荐答案

它没有。只有主线程被暂停,因为它是从主线程调用的。如果你从实际的线程方法中调用它,它只会暂停线程。这样的事情:

It does not. Only the main thread is paused because it is called from the main thread. It will only pause the thread if you call it from the actual thread method. Something like this:
Thread t = new Thread(Work);
t.Start();

public static void Work(object data) 
{
  Thread.Sleep(1000);
}



祝你好运!


Good luck!


这篇关于Thread.Sleep如何暂停工作线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆