tags:

views:

97

answers:

2

Ok, I'm looking for something pretty simple: creating a MessageBox that doesn't stop my code.

I'm guessing I'll have to create a different thread or something? Please advise on the best way to accomplish this.

Thanks!

+7  A: 

No, You're going to have to make your own message box form. the MessageBox class only supports .ShowDialog() which is a modal operation.

Just create a new form that takes parameters and use those to build up a styled message box to your liking.

Aren
Ok gotcha, so I just have to create my own form. Very doable, thanks!
Soo
+1  A: 

You could spin up another message pump by calling it on separate thread. MessageBox.Show pumps message so it is safe to do without a call to Application.Run.

public void ShowMessageBox()
{
  var thread = new Thread(
    () =>
    {
      MessageBox.Show(...);
    });
  thread.Start();
}
Brian Gideon
`ThreadPool.QueueUserWorkItem(delegate {MessageBox.Show("Text");});` :)
Markus
@Markus: That would do the trick as well except it would hang up a `ThreadPool` thread which would not be a good practice generally speaking.
Brian Gideon
Indeed, you're right.
Markus
In Brian's code example, how to I stop the thread (and close it?) when the messagebox is closed. Multithreading is very mysterious and new to me, so the inner workings of having another thread are beyond me.
Soo
@Soo: You don't have to do anything special. Once the `MessageBox` is closed the thread will end gracefully.
Brian Gideon