c# - MessageBox.Show() 卡住执行 : windows form c#

标签 c# winforms messagebox

美好的一天。我有一张表格和一个背景 worker 。在 bw_Dowork 事件中,有些情况下我需要使用 MessageBox.Show()(即是?否框)打印消息。但是,每当我调用 messageBox.Show() 方法时,执行都会卡住并且表单不允许我单击我的选择(即是/否)。有时,如果我想工作,我必须按照消息显示的速度快速单击。否则,当我给出一秒钟的间隙时它会卡住。我使用 MessageBox.Show() 的实例示例如下所示:

private void bw_DoWork(object sender, DoWorkEventArgs e)
{
    if (fileFTP.Exists == false)
    {
        _busy.WaitOne();

        if ((worker.CancellationPending == true))
        {
            e.Cancel = true;
            return;
        }

        SetText("File Ftp.exe are missing. This file are required to preform update, please contact yout system administrator to retrive Ftp.exe", true);
        MessageBox.Show("File Ftp.exe are missing. This file are required to preform update, please contact yout system administrator to retrive Ftp.exe");
        goto ExitProgram;
    }  
}

我在网上对此做了一些研究,有人建议 MessageBox 干扰了界面线程。这使我使用委托(delegate)触发消息,但都无济于事。我不得不删除所有的消息框。离开一个仍然会在被解雇时卡住我的执行。请提供任何帮助。

最佳答案

尝试使用主 UI 线程来显示消息框:

this.BeginInvoke((Action)(() => MessageBox.Show("Hello")));

(假设this 是一个表单)

顺便说一句:“转到”?严重吗?

关于c# - MessageBox.Show() 卡住执行 : windows form c#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19856017/

相关文章:

Extjs:警报消息框位置

c - Windows AT&T 程序集中的 MessageBoxA

c# - 命名空间 'Transactions' 中不存在类型或命名空间名称 'System'

c# - 在 WPF 的代码隐藏中更改字体样式

c# - 找不到程序集中嵌入的资源 EntityModel.rlinq

vb.net - 显示两个 RichTextBox 控件之间的区别

c# - 仅绘制 TableLayoutPanel 单元格的外边框

c# - 将对象列表写入文本文件

c# - 东亚本地化软件中的访问/快捷键?

c# - 消息框出现两次 C#