MessageBox.Show()冻结执行:windows表单c#

Nur*_*ihu 4 c# messagebox winforms

美好的一天.我有一个表格和一个背景工作者.在bw_Dowork事件中,有些情况需要使用MessageBox.Show()打印消息(即YES?NO框).但是,每当我调用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;
    }  
}
Run Code Online (Sandbox Code Playgroud)

在我对网上做了一些研究之后,有人建议MessageBox干扰接口线程.这使我使用代理触发消息,但都无济于事.我不得不删除所有的MessageBoxes.离开时仍然会在被解雇时冻结我的执行.请任何帮助将不胜感激.

qwe*_*oyo 9

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

this.BeginInvoke((Action)(() => MessageBox.Show("Hello")));
Run Code Online (Sandbox Code Playgroud)

(假设是一个表格)

顺便说一句:"转到"?当真?

  • 当我看到`goto`时我的想法!:d (4认同)
  • 我认为所有转到"用户"很久以前就已经死了.:p (2认同)