I’m trying to make a message box modal but I’m running into threading issues.
I have a class like this:
public static class DisplayMessage()
{
public static void ErrorMessage(string errorMessage)
{
MessageBox.Show(errorMessage, "Error", MessageBoxButtons.OK,MessageBoxIcon.Error);
}
//other similar methods
}
So I want the message box to be modal to the main form. MessageBox.Show is overloaded so that you can specify an IWin32Window. So I tried using .ActiveForm but I get this:
Cross-thread operation not valid: Control accessed from a thread other
than the thread it was created on.
Try this: