Multiple message threads in single app

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have an app with two forms which are displayed at the same time. When
either of these opens a modal child form both are disabled intil the modal
child is closed. Is there a way to prevent this from happening? I believe I
need to create two independent message threads but I have no idea how.
 
You can emulate modal form without using it like:
Form parentForm...
....
Form pseudoDialogForm = new Form()
pseudoDialogForm.Owner = parentForm;

Disable parent form before showing pseudoDialogForm and enable it after
closing.
 
Vladimir,

This is not the solution for his problem. The modal form prevents switching
over any form ran from the same message loop.

RFlaugher, you got the idea right, you need to run two UI threads (separate
message loop) in order to achieve what you are after. Running second UI
thread isvery easy.
1. Create new thread and specify its thread proc. Inside the thread proc
create the second form and then display it using Application.Run. Basically
this is the same code that you can find in the application Main method.
There are couple of things that you need to do to setup the second thread
correctly: first is to set the threads appartment to STAThread and second
probably is to set the new thread not to be a background thread. The latter
depends on the logic of your application.

Keep in mind though that having both forms running in separate threads may
hamper the communication between them.
 
Back
Top