如何使较新的线程进入睡眠状态

编程入门 行业动态 更新时间:2024-10-23 08:27:40
本文介绍了如何使较新的线程进入睡眠状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已将线程创建为

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

更多推荐

如何使较新的线程进入睡眠状态

本文发布于:2023-11-27 12:15:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1638032.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:线程   睡眠   状态   使较新

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!