是否MessageBox.Show()会自动马歇尔到UI线程? [英] Does MessageBox.Show() automatically marshall to the UI Thread?

查看:236
本文介绍了是否MessageBox.Show()会自动马歇尔到UI线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我启动通过ThreadPool.QueueUserWorkItem一个线程有它一个消息对话:

I launch a thread via ThreadPool.QueueUserWorkItem which has a messagebox dialogue in it:

System.Windows.Forms.DialogResult博士= System.Windows.Forms.MessageBox.Show(你想下载的升级背景..?,升级可用,MessageBoxButtons.YesNo);

System.Windows.Forms.DialogResult dr = System.Windows.Forms.MessageBox.Show("would you like to download upgrade in background? ..", "Upgrade Available", MessageBoxButtons.YesNo);

这似乎很好地工作但我有点怀疑后,一些客户认为他们没有得到消息弹出。我在.NET框架的感觉2.0+你不需要名帅这个特殊的电话,它会为你。是否正确?

It seems to work fine however I am a little suspicious after some customers suggested they were not getting the message popping up. I had the feeling in .NET framework 2.0+ you do not need to marshal this particular call, it does it for you. Correct?

这是为利息半相关的主题:
为什么MessageBox.Show使用的所有者窗口?

This is a semi-related topic for interest: Why use a owner window in MessageBox.Show?

推荐答案

没有,它没有元帅到UI线程。如果你仔细想想,它不可能为它这样做。

No, it doesn't Marshal to the UI thread. If you think about it, it wouldn't be possible for it to do so.

这是可能的有一个以上的UI线程在应用程序中。一些程序,如Internet Explorer,有很多UI线程。这UI线程将在.Show叫挑?

It's possible to have more than one UI thread in an application. Some programs, such as internet explorer, have many UI threads. Which UI thread would the .Show call pick?

也有可能在没有UI线程应用程序使用MessageBox.Show。可以很好地在一个控制台应用程序调用这一点,它会工作。

It's also possible to use MessageBox.Show in an application that has no UI threads. You can very well call this in a Console application and it will work.

MessageBox.Show将显示它的线程从呼吁UI。如果尚未对线程消息泵的运行它会设置一个临时才能发挥作用。显示调用完成后,它会撕裂下来。

MessageBox.Show will show UI on the thread it is called from. If there isn't already a message pump running on the thread it will setup a temporary one in order to function. It will tear it down after the Show call completes.

这篇关于是否MessageBox.Show()会自动马歇尔到UI线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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