I'm working on adding a message box method that will allow me to display a message to the user without waiting for the user to answer. I've done this by starting MessageBox.Show in a separate thread.
I also use a static DialogResult variable to allow me to see the user's result in my calling code. My method also accepts a MessageBoxButtons parameter that is then passed on to the MessageBox.Show method.
The only problem is that I will need to close the box later on by calling another method. I've tried Thread.Abort and Thread.Interrupt but neither close the dialog.
Here is my current code for clarity (all contained in static Log):
Expand|Select|Wrap|Line Numbers
- public static void writeMessage(string LogType, string Error, MessageBoxButtons buttonSet)
- {
- MessageData data = new MessageData();
- data.message = Error;
- data.LogType = LogType;
- data.buttons = buttonSet;
- messageThread = new Thread(new ParameterizedThreadStart(Log.displayMessage));
- messageThread.Start(data);
- }
- public static void closeMessage()
- {
- messageThread.Interrupt();
- }
- private class MessageData
- {
- public string message;
- public string LogType;
- public MessageBoxButtons buttons;
- }
- private static void displayMessage(object data)
- {
- MessageData d = (MessageData)data;
- Log.lastMessageResult = DialogResult.None;
- Log.lastMessageResult = MessageBox.Show(d.message, d.LogType, d.buttons);
- }
Thanks in advance,
Fr33dan