Application.DoEvents(),并冻结了一些机器上 [英] Application.DoEvents() and freezing on some machine

查看:172
本文介绍了Application.DoEvents(),并冻结了一些机器上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WinForms应用程序,它会调用Application.DoEvents()。现在,应用程序死机解决此方法被调用时(毫不奇怪)。

I have a winforms application which makes calls to Application.DoEvents(). Now the app freezes around the time this method is called (no surprise).

不过,这只是发生在一些机器上。它是公平地说,这将是由于机器本身还是仍然下跌到code / application.doevents()?在这种情况下,它应该被重构以使用的BackgroundWorker

However, this only happens on some machines. Is it fair to say that this would be due to machine itself or is it still down to the code/application.doevents()? In which case, it should be refactored to use backgroundworker.

这将是一个机器/环境问题或奥珀蒂尼蒂使用的BackgroundWorker?

Would this be a machine/environment issue or an oppurtunity to use backgroundworker?

推荐答案

如果你可以使用背景工人。 的DoEvents 是黑客,让您的应用程序保持响应和处理WM_PAINT消息主要是,当它做一些事情的它实际上应该永远做的:阻断执行以上在主GUI循环消息处理期间在合理的时间。如果的DoEvents 引起挂起,而不是修复它,你有太多的信息花费了太多的系统电源。 有些机器变成最机器,否则

Use a background worker if you can. DoEvents is a 'hack' to allow your application to remain responsive, and process WM_PAINT messages mostly, when it's doing something it should actually never be doing: blocking execution for more than a reasonable time during message processing in the main GUI loop. If DoEvents causes a hang instead of fixing it, you have too many messages spending way too much system power. Fork them out to background workers to fix all of it at once - it's just a matter of time before "some machines" becomes "most machines" otherwise.

这篇关于Application.DoEvents(),并冻结了一些机器上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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