Thread.Sleep(xxx)邪恶也是Thread.Sleep(0)邪恶吗? [英] Thread.Sleep(xxx) evil is Thread.Sleep(0) evil too?

查看:173
本文介绍了Thread.Sleep(xxx)邪恶也是Thread.Sleep(0)邪恶吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我知道Thread.Sleep(number)被锁定,因为它锁定了UI线程,但是在阅读C#线程指南时却使用Thread.Sleep(0);将控制权交给另一个线程.在过去的一些代码中,烦人的等待是等待通过Thread.Sleep(100)将Thread.Sleep(0)释放由Threading引起的事情.表单什么也不做,不用等待就释放了所有东西!
请使用Opions!

Glenn

Hi All,

I know Thread.Sleep(number) is looked down upon as it locks the UI thread however reading a C# threading guide it uses Thread.Sleep(0); to give control to another thread. In some of past code there was annoying waits for things that was caused by the Threading were freed up via a Thread.Sleep(100) will Thread.Sleep(0); free up things with out a wait while the form does nothing!
Opions please!

Glenn

推荐答案

See Here[^] 5th Para down.

But yeah, generally, try to avoid them.


您最好进行异步调用,其中,最终调用会调用将数据/图像/等带到gui线程的委托.
通过异步,GUI线程不会锁定,并且处理会继续进行.它为系统提供了更好的响应能力.您可以创建中止呼叫,因为按钮可以继续工作....
You better do asynchronous calls where the endcall invokes a delegate that brings data / image / etc to the gui thread.
With asynchronity the GUI thread doesn''t lock and the processing goes on. It gives better responsiveness to the system. You can create an abort call because buttons keep working....


这篇关于Thread.Sleep(xxx)邪恶也是Thread.Sleep(0)邪恶吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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