DoEvents()在FormClosing中是否也是邪恶的? [英] Is DoEvents() also evil in FormClosing?

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

问题描述

关于另一个我建议使用的问题

On a different question I suggested to use

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
    while (processingLock)
        Application.DoEvents();
}

在FormClosing事件中

(在完成冗长的计算后,processingLock立即变为false).这样做的目的是使应用程序有序地关闭,并且原始发布者不使用线程.

in the FormClosing event (with processingLock becoming false immediately after a lengthy calculation was done). It should serve the purpose to have the application close down in an orderly manner and the original poster didn't use threads.

在我的建议答案中,有人评论说DoEvents从来都不是一件好事,它提供了以下链接:使用Application.DoEvents()

On my suggested answer somebody commented that DoEvents is never good, providing this link: Use of Application.DoEvents()

我阅读并且(我认为)理解了这个问题.我认为(仍然是废话)如果我在FormClosing事件中使用上述DoEvents的话,就不会发生混淆事件的风险-如果没有办法取消用户的关闭操作(如设置e.Cancel = true)

I read and (I think) understood the issue. In my opinion (which is still noobish) there is no risk for confusing events to happen if I use DoEvents as above in the FormClosing event - if there is no way to cancel the closing for the user (like setting e.Cancel = true).

我的问题:这是确保应用程序正常终止的有效方法吗?如果不能,为什么?

My question: is this a valid method to make sure an application is terminated well and if not, why?

推荐答案

感谢评论,并且对

Thanks to comments and more thinking about the relevant posts I've figured out why this "special case" with FormClosing is not special after all.

问题是在FormClosing事件期间,禁用了表单.用户不仅可以尝试多次关闭表单(在这种情况下可以这样做),而且还可以单击任何其他UI元素-导致执行顺序不确定等问题.在链接的文章中提到.

The problem is that the form is not disabled during the FormClosing event. The user can not only try to close the form several times (which would be okay in this scenario), but she can also click any other UI elements - leading to the problems with uncertain execution order etc. that are mentioned in the linked article.

菜鸟的硬概念,谢谢您的输入.

Hard concept for noobs, thanks for you input.

这篇关于DoEvents()在FormClosing中是否也是邪恶的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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