如何使较新的线程进入睡眠状态 [英] how to make newer a thread sleep

查看:72
本文介绍了如何使较新的线程进入睡眠状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将线程创建为

I have created thread as

Thread th = new Thread(DoSomething);
    th.IsBackground = true;


th.sleep();无法正常工作
但同时主线程


but th.sleep(); not working
but at the same time main thread

System.Threading.Thread.Sleep(1000);


工作正常
请建议


working fine
Please suggest

推荐答案

不起作用"的意思是:它将无法编译.没错.

方法System.Threading.Thread.Sleep是静态的.您不需要线程引用来指示应该执行哪个线程:要进入睡眠状态的线程是当前线程.这样,代码线程只能使运行该代码的同一线程进入睡眠状态.这是所有线程系统的常见范例.

—SA
"Not working" means: it won''t compile. That''s correct.

The method System.Threading.Thread.Sleep is static. You don''t need a thread reference to indicate what thread should be effected: the thread to be put to sleep is the current thread. In this way, a code thread can put to sleep only the same thread running this code. This is a common paradigm of all threaded systems.

—SA


这篇关于如何使较新的线程进入睡眠状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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