4
Answers

Problem displaying a messageBox

Alex

Alex

17y
2.7k
1
Hi,

I'm working on a WinForm application with .NET CF 2.0 and I have a background running thread that needs to notify the user about various events. The problem is that everytime I want to notify the user with a MessageBox about an event, the application exits once the messagebox is displayed...I get the following message in the output window: The thread 0x2eda2a2 has exited with code 0 (0x0).

However, if I display the message in a label of my form, everything works well...here is the code I use:
  1. public void DisplayMessage(string message)
  2.         {
  3.             if (InvokeRequired)
  4.             {
  5.                 DisplayMessageDelegate displayMessageDelegate = new DisplayMessageDelegate(DisplayMessage);
  6.                 this.Invoke(displayMessageDelegate, new object[] { message });
  7.             }
  8.             else
  9.             {
  10.                 this.labelStatus.Text = message;  // Works well
  11.                 MessageBox.Show(message, "Info", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); // Application exits when called
  12.                
  13.             }
  14.         }

Thanks in advance!
alex

Answers (4)