views:

2730

answers:

3

I have a Winforms application that uses show multiple top-level windows:

Form1 form1 = new Form1();
form1.Show();
Form2 form2 = new Form2();
form2.Show();
Application.Run();

Inside one of the event-handlers in Form1, I would like to be able to show a modal dialog:

Dialog dialog = new Dialog();
dialog.ShowDialog(form1);

without suspending the other top-level window.

Is this possible?

+4  A: 

You'd need to run each top-level window on its own STA thread to achieve that, I believe.

HTH, Kent

Kent Boogaart
+1  A: 

If you need an alternate method to running multiple UI threads, you can handle the WM_ENABLE message and use the EnableWindow method to prevent the Form from being disabled.

Mo Flanagan
A: 

Once you show a modal dialog, it will make all other windows on the same STA thread unusable. The reason behind this is the modal dialog will start intercepting all messages for that particular thread. The other top level windows will not be able to respond until the modal dialog is closed.

JaredPar
The reason the windows stop responding is because .NET loops through each top level window on the thread and calls EnableWindow(false).
Mo Flanagan