Non-autoblocking MessageBoxes in c#
Anyone know a messageBox in .NET that doesn't block the thread that cr开发者_C百科eated it untill it's closed ?
private void ShowMessageBox(string text, string caption)
{
Thread t = new Thread(() => MyMessageBox(text, caption));
t.Start();
}
private void MyMessageBox(object text, object caption)
{
MessageBox.Show((string)text, (string)caption);
}
You can call ShowMessageBox()
with your text and caption. This is just a simple sample, you can add buttons or icons owner or other arguments you want.
You can simplify these other answers down to one line of code
new Thread(() => System.Windows.Forms.MessageBox.Show(text)).Start();
Probably the simplest is:
Thread t = new Thread(() => MessageBox.Show(text));
t.Start();
The default MessageBox
which you are using through System.Windows.Forms
namespace will always be Modal (i.e., Blocking). If you want to have a Modeless message box, you should create your own WindowsForm
that looks like a MessageBox
.
You will then display this Form as follows:
// C#
//Display frmAbout as a modeless dialog
Form f= new Form();
f.Show();
精彩评论