从异步线程与Form1中调用的MessageBox父 [英] Call MessageBox from async thread with Form1 as parent
本文介绍了从异步线程与Form1中调用的MessageBox父的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
点击按钮1
放在 Form1中
,程序检查如果新版本可用(通过互联网)之后,但在新的线程这样做(不冻结检查过程中,形式)。结果
当新版本发现还是不行,相应的的MessageBox
是显示,但它没有父(因为它是从线程的调用,而不是直接在 Form1中
)。
如何使 Form1中
为的MessageBox
显示?父
解决方案
this.Invoke(新动作(()=> { MessageBox.Show(这一点,文本);}));
这将切换到主线程,并显示消息框与 Form1中
父。
After clicking button1
placed on form1
, program is checking if the new version is available (via internet), but doing this in the new thread (not to freeze the form during check).
When the new version is found or not, the appropriate MessageBox
is shown, but it has no parent (because it was called from the thread, not directly from the form1
).
How to make the MessageBox
display with form1
as a parent?
解决方案
this.Invoke(new Action(() => { MessageBox.Show(this, "text"); }));
This will switch to main thread and show MessageBox with form1
parent.
这篇关于从异步线程与Form1中调用的MessageBox父的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文