MessageBox.Show() 是否自动编组到 UI 线程? [英] Does MessageBox.Show() automatically marshall to the UI Thread?

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

问题描述

我通过 ThreadPool.QueueUserWorkItem 启动了一个线程,其中有一个消息框对话框:

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

System.Windows.Forms.DialogResult dr = 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 线程..Show 调用会选择哪个 UI 线程?

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.如果线程上还没有消息泵在运行,它将设置一个临时的以便正常运行.它将在 Show 调用完成后将其拆除.

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天全站免登陆