建议一的MessageBox.show更换不阻塞GUI线程? [英] Suggestions for a MessageBox.Show replacement that does not block GUI thread?

查看:1838
本文介绍了建议一的MessageBox.show更换不阻塞GUI线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

而回,我跑过的情况下,我们需要显示的消息框,为通知的用户,但我们不能使用的MessageBox.show,因为它会阻止GUI线程(所以没有在屏幕上得到更新,而对话框活性)。在一个替代任何建议?

a while back I ran across a situation where we needed to display message-boxes to the user for notifications but we could not use MessageBox.Show because it blocks the GUI thread (so nothing on the screen gets updated while the dialog is active). Any suggestions on an alternative?

[I codeD当时是一个选择,但我不喜欢它。如果没有更好的出现,虽然我会后它作为一个答案]

[I coded an alternative at the time but I don't like it. I'll post it as an answer if nothing better appears though]

编辑:对话框必须浮在主窗口的顶部;如果它出现在任务栏与否我不在乎。不止一个对话框可能在某些情况下被激活一次。

the dialog must float on top of the main window; i don't care if it appears in the taskbar or not. More than one dialog may be active at once in certain circumstances.

附录:我的解决方案是,提供的确定和取消按钮发出已完成和已取消事件的基表; OK称为虚拟是validateData的子类覆盖。使用的属性,以避免每次重新创建形式主叫形式(形式只是隐藏,而不是封闭的),并在活性形式字典来prevent相同的形式被激活一次以上。这看起来像一个模态形式,支持一次多个弹出的形式,但不占用主界面线程。

ADDENDUM: my solution was a base form that provided OK and CANCEL buttons to emit Completed and Cancelled events; OK called a virtual ValidateData for subclass override. The calling form used properties to avoid recreating the form each time (the form was just hidden instead of closed) and kept a dictionary of active forms to prevent the same form from being activated more than once. This looks like a modal form, supports multiple pop-up forms at once, but does not tie up the main GUI thread.

推荐答案

我同意rslite和米切尔卖家。创建一个非模态的形式来显示所需的信息是去的最佳途径。如果您有多个消息,您可能要考虑将它们放入一个列表框,并且对它们的用户双击得到完整的信息需要被显示出来。

I agree with rslite and Mitchel Sellers. Creating a non-Modal form to display the information needed is the best route to go. If you have multiple messages, you might want to consider putting them into a ListBox and have the user double-click on them to get the full information needing to be displayed.

这篇关于建议一的MessageBox.show更换不阻塞GUI线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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