DoEvents和BackgroundWorker之间的区别 [英] Difference between DoEvents and BackgroundWorker

查看:79
本文介绍了DoEvents和BackgroundWorker之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

DoEvents BackgroundWorker有什么区别?

推荐答案

它们实际上是2种不同的东西. DoEvents 只是给当前线程一个处理所有未决消息的机会.理想情况下,您永远不必使用它.如果您希望UI具有响应能力,请在辅助线程中执行所有繁重的任务,而BackgroundWorker 使其非常容易做到这一点.
They are 2 different things really. DoEvents just gives the current thread a chance to handle all pending messages. Ideally you should never have to use it. If you want the UI to be responsive, do all your heavy tasks in secondary threads and the BackgroundWorker makes it really easy to do this.


最重要的区别:DoEvents不是一个多线程工具,它可以在UI线程中工作,并传递所有阻塞调用者的消息.这就是为什么它通常无法解决某些人希望解决的问题的原因.经验法则从未使用过它. (法力是对的.)

BackgroundWorker在不同的线程中工作,非常适合许多冗长的任务,而无需挂起UI.局限性:该技术不太适合生成无限"任务(与应用程序寿命相同).为此,常规线程更好.

谢谢.
—SA
Most important difference: DoEvents is not a multi-threading tools, it works in UI thread and passes all the messages blocking the caller for this time. That''s why it usually don''t resolve the problem some people hope to solve. Rule of thumb is never using it. (Manas is right.)

BackgroundWorker works in a different thread, good for many lengthy tasks without hanging the UI. Limitation: this technique is not well suited to spawn "infinite" tasks (of the same lifetime as the application). For this purpose, regular thread is better.

Thank you.
—SA


简短答案:不要打扰,不要使用DoEvents()

长答案:backgroundworker非常聪明并且足够先进,可以处理交叉线程.
short answer: Don''t bother and DO NOT USE DoEvents()

long answer : backgroundworker is quite smart and advanced enough to handle cross thread.


这篇关于DoEvents和BackgroundWorker之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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