4

Good day. I have a form and one backgroundworker . In the bw_Dowork event, there are instances when I need to print a message using MessageBox.Show()(i.e YES?NO box). However, whenever I call the messageBox.Show() method, the execution freezes and the form does not allow me to click my selection (i.e either Yes/No). Sometimes, if I want to work, I have to click fast as the message shows. Otherwise it freezes when I give a seconds of gap. Example of an instance where I use MessageBox.Show() is as shown below:

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;
    }  
}

After I did some research about this online, some suggested the MessageBox is interfering with the interface thread. This makes me trigger the Messages using delegates but all to no avail. I had to remove all the MessageBoxes. Leaving one still freezes my execution when fired. Please any help would be appreciated.

Abbas
  • 14,186
  • 6
  • 41
  • 72
Nuru Salihu
  • 4,756
  • 17
  • 65
  • 116
  • possible duplicate of [Popping a MessageBox for the main app with Backgroundworker in WPF](http://stackoverflow.com/questions/3104661/popping-a-messagebox-for-the-main-app-with-backgroundworker-in-wpf) – Kami Nov 08 '13 at 09:55
  • sounds strange. It is not frozen for me. – King King Nov 08 '13 at 10:27

1 Answers1

9

Try to use the main UI thread to show the messagebox:

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

(assuming this is a Form)

Btw: "goto"? seriously?

qwertoyo
  • 1,332
  • 2
  • 15
  • 31