MDI forms and threading

paulinda

Newcomer
Joined
Apr 26, 2006
Messages
2
I have a project that includes a main form that is an MDI parent. Other projects will create libraries that contain forms to be displayed in the parent form. Each child form will be in it's own thread and the parent form will control the thread.

The problem is if I don't use threading, I can set the parent property of the child form but then I can't stop or start the child form. If I use threading, I can start and stop the child form but I can't set the parent property of the child form to the parent form.

I've been able to hack it together but it requires that the libraries make thread safe calls to the parent form whenever they need to update the child form. The idea is that the libraries could be created to just plug-in to the parent process or could stand alone if needed.

Any ideas? Thanks.
 
Is there a reason why you need each form to run on it's own thread? The window only needs to respond to user actions on the app's main thread (technically it is dealing with incoming window messages) and the message pump isn't itself multithreaded. If your forms are doing cpu intensive or long running operations then they can spawn their own threads for this work.

All window updates need to be performed on the application's main thread anyway otherwise you will encounter issues / runtime errors - one window running on one thread updating the state of another window on a different thread is asking for trouble.
 
Last edited:
You are probably right. I thought that it would be easier to control the child form if it was in it's own thread. I can create the same functionality with events but the child form will have to check state periodically to see if it should continue or wait.

Thanks for the help.
 
Back
Top