Multiple message threads in single app

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.
 
V

Vladimir Matveev

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.
 
S

Stoitcho Goutsev \(100\)

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top