Click here to Skip to main content
15,905,967 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I need some information regarding to MDI application.
I need to create an MDI apllication, but each child form of the MDI application will be having a lot of UI operations for itself. So I want to create the MDI child in a separate thread and let it run by itself, i.e. if anything make that MDI child hang up/crash, the MDI parent will still go on.
I found some similar samples, but they are developed in WPF.
For me, I need to use the Windows Forms MDI application.
Is it possible to do so?
Providing any relating information will be very grateful.

Thanks & best regards,
Zaw Min Tun
Posted

Dear SAKryukov,

Thanks a lot for the answer and the links.
I will browse the links and learn.

But, can I make one more naive question? Is it correct to say that Calling Invoke or BeginInvoke will force the code lines to run back in the same thread which created that Control or MDI Child?

Thanks again for your time, a lot.

Best regards,
Zaw Min Tun
 
Share this answer
 
Wrong idea. Threads are not related to Forms and Controls. You can run different threads each updating the same and different controls. Let's see.

First, how to run threads and work with UI.

You cannot call anything related to UI from non-UI thread. Instead, you need to use the method Invoke or BeginInvoke of System.Windows.Threading.Dispatcher (for both Forms or WPF) or System.Windows.Forms.Control (Forms only).

You will find detailed explanation of how it works and code samples in my past answers:
Control.Invoke() vs. Control.BeginInvoke()[^],
Problem with Treeview Scanner And MD5[^].

See also more references on threading:
How to get a keydown event to operate on a different thread in vb.net[^],
Control events not firing after enable disable + multithreading[^].

Now, I doubt you really need MDI. You don't want it, really. This style is highly discouraged by everyone, and Microsoft, first of all. Implementation using MDI is more difficult, and you don't want to scare off your users with immense inconvenience of it.

Please see:
http://en.wikipedia.org/wiki/Multiple_document_interface#Disadvantages[^],
Question on using MDI windows in WPF[^],
MDIContainer giving error[^].

In my past solutions referenced above I also suggest what to do instead.

—SA
 
Share this answer
 
To answer your question at top level, all the user interface (UI) updates will be sent back to the main thread, (UI Thread). Any calculations ect will be handled on your secondary thread. So for instance, if you change the text property of a textbox, it will be dispatched to the main thread if you use Invokek, but if you first calculate the value of a the textbox then it will be calculated on your secondary thread.

Please read the articles above, it is very informative and written by a knowledgeable person.

Kind Regards

Terence
 
Share this answer
 
Thanks a lot, Terence.

Best regards,
Zaw Min Tun
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900