Thread.sleep代码... [英] Thread.Sleep...

查看:120
本文介绍了Thread.sleep代码...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




目前我的线程正在旋转并且正在做一个

Thread.Sleep(someTime)。


我想把它改成Thread.Sleep(Timeout.Infinite);然后

当我在一个集合中有实际数据要在这个线程中处理时,我是_
要做一个_thread.Interrupt();这会是一个更好的方法吗?

旋转线程?

Hi,

Currently I have a thread thats spinning and doing a
Thread.Sleep(someTime).

I was thinking of changing this to Thread.Sleep(Timeout.Infinite); then
when I have actual data in a collection to process in this thread, I was
going to do a _thread.Interrupt(); Would this be a better approach to
spinning a thread on ?

推荐答案

news.microsoft.com< di * *******@discussion.microsoft.com>写道:
news.microsoft.com <di********@discussion.microsoft.com> wrote:
目前我有一个线程正在旋转并做一个
Thread.Sleep(someTime)。

我想把它改成Thread.Sleep( Timeout.Infinite);然后当我在一个集合中有实际数据来处理这个帖子时,我就是要做一个_thread.Interrupt();这是一个更好的方法来旋转线程吗?
Currently I have a thread thats spinning and doing a
Thread.Sleep(someTime).

I was thinking of changing this to Thread.Sleep(Timeout.Infinite); then
when I have actual data in a collection to process in this thread, I was
going to do a _thread.Interrupt(); Would this be a better approach to
spinning a thread on ?




更好的方法仍然是使用Monitor.Wait和Monitor.Pulse。 />

-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet

如果回复该群组,请不要给我发邮件



A better approach still would be to use Monitor.Wait and Monitor.Pulse.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Jon,

你写线程代码的时间有多长?


-

-----------

有TidBits吗?

在这里获取: www.networkip.net/tidbits

" Jon Skeet [C#MVP]" < SK *** @ pobox.com>在消息中写道

新闻:MP ************************ @ msnews.microsoft.c om ...
Jon,
how long you been writing thread code?

--
-----------
Got TidBits?
Get it here: www.networkip.net/tidbits
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
news.microsoft.com< di ******** @ discussion.microsoft.com>写道:
news.microsoft.com <di********@discussion.microsoft.com> wrote:
目前我有一个线程正在旋转并做一个
Thread.Sleep(someTime)。

我想把它改成Thread.Sleep( Timeout.Infinite);
然后当我在一个集合中有实际数据来处理这个帖子时,我就是要做一个_thread.Interrupt();这是一个更好的方法来旋转线程吗?
Currently I have a thread thats spinning and doing a
Thread.Sleep(someTime).

I was thinking of changing this to Thread.Sleep(Timeout.Infinite); then when I have actual data in a collection to process in this thread, I was
going to do a _thread.Interrupt(); Would this be a better approach to
spinning a thread on ?



更好的方法仍然是使用Monitor.Wait和Monitor.Pulse。

-
Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet
如果回复该组,请不要给我发邮件



A better approach still would be to use Monitor.Wait and Monitor.Pulse.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too



你可以使用Q.Sychronized包装而不必使用lock(q)blah


你唯一需要使用锁(q)的时候是你正在使用IEnumerator作为

它的内乱无法拼写不是线程安全的。


所以代码库中更简单的方法是睡觉infinte然后

打断那个。


" Alvin Bruney" < vapordan_spam_me_not@hotmail_no_spamhotmail.com>写在

消息新闻:eZ ************** @ TK2MSFTNGP09.phx.gbl ...
You can use the Q.Sychronized wrapper and not have to use lock(q) blah

The only time u need to use the lock(q) is when you are using IEnumerator as
its intrisincally blah cant spell not thread safe.

So the simpler approach in a code base would be to sleep infinte and then
interrupt that.

"Alvin Bruney" <vapordan_spam_me_not@hotmail_no_spamhotmail.com > wrote in
message news:eZ**************@TK2MSFTNGP09.phx.gbl...
Jon,你写线程代码多久了?

-

-----------
有TidBits吗?
获取它在这里: www.networkip.net/tidbits
" Jon Skeet [C#MVP]" < SK *** @ pobox.com>在消息中写道
新闻:MP ************************ @ msnews.microsoft.c om ...
Jon,
how long you been writing thread code?

--
-----------
Got TidBits?
Get it here: www.networkip.net/tidbits
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
news.microsoft.com< di ******** @ discussion.microsoft.com>写道:
news.microsoft.com <di********@discussion.microsoft.com> wrote:
目前我有一个线程正在旋转并做一个
Thread.Sleep(someTime)。

我想把它改成Thread.Sleep( Timeout.Infinite);然后,当我在一个集合中有实际数据要在这个线程中处理时,我
将要做一个_thread.Interrupt();这是一个更好的方法
来旋转线程吗?
Currently I have a thread thats spinning and doing a
Thread.Sleep(someTime).

I was thinking of changing this to Thread.Sleep(Timeout.Infinite); then when I have actual data in a collection to process in this thread, I was going to do a _thread.Interrupt(); Would this be a better approach to spinning a thread on ?



更好的方法仍然是使用Monitor.Wait和Monitor.Pulse。

-
Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet
如果回复该组,请不要给我发邮件



A better approach still would be to use Monitor.Wait and Monitor.Pulse.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too




这篇关于Thread.sleep代码...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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