Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi All,
How may I open a "new form" in a new tabPage of an already existing tabControl on a separate thread. My concept of threading is very acute and i dont know how to accomplish this. If you may please help me out with some useful webpages and tutorials or may be even with the code snippet, it would be very kind of you.

Thanks in advance!!!
Posted
Comments
Telstra 7-May-14 5:13am    
will you explain little more as this is confusing. try to post image or code snippet what you done and what you want to do.
sovit agarwal 7-May-14 5:46am    
Just like in MS Word , when we click on "OPEN" or "NEW", a document is loaded using a different thread and all the processing on that doc is carried out using that thread.
Similarly, i have a form and my application requires that whenever i click on "NEW" or "LOAD" button on the MENU bar, the "main form" should be loaded on a separate thread and all the processing that has to be carried out is to be done on that thread.
But this doesn't imply that the previous form be closed.Both the forms will run simultaneously.

Based on your comment that you want something that behaves a little like MSWord...

Option 1 - You could just start another instance of your program - this will be running in it's own thread (I believe). e.g.
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = Application.ExecutablePath;
proc.Start();

Option 2 - You can load the form (again) under a new thread e.g.
C#
var t = new System.Threading.Thread(RunFormInNewThread);
    t.Start();
...
public static void RunFormInNewThread()
{
     Application.Run(new Form1());
}
(This is probably closer to how MSWord works as there is only one instance of the exe)

Option 3 - You can have a process running in the background on it's own thread (but I don't think this is really what you are after)

This link might help Threading Tutorial[^]
and also the responses to this SO post[^]

Also found this free e-book http://www.albahari.com/threading/[^]
 
Share this answer
 
v2
It is a bad idea to use several UI threads, it will give you loads of strange situations to maintain but it is possible of cause, only the same tabcontrol cannot be owned by multiple threads and a tabstrib is a control in a collection of tabstribs on a tabcontrol.

so the standard getting a new thread for a form with own message loop i suppose you know:
http://msdn.microsoft.com/en-us/library/ms157902.aspx

What you want to do is to seperate the load from the displaying so that you are not opening it on another thread, but WITH another. consider for instance having a TASK tell your user interface when it has loaded data for your new tab and it can be shown/ selected/ updated as you wish.
http://msdn.microsoft.com/en-us/library/jj155756.aspx

or you could go for the more old fashioned way and use the threadpool yourself:
http://msdn.microsoft.com/en-us/library/3dasc8as.aspx

Last option is an old favoured wrapper known as the background worker, you could assign one specific for each tabstrib, but i'd propably go for one of the former: http://msdn.microsoft.com/en-us/library/vstudio/system.componentmodel.backgroundworker

Whatever way you use you can then assign the load task and any other for any assignment of the program to a work thread and let the gui idle around pleasing the user until the results are ready.
On Generally handling threads yourself, you may find this usefull as well
http://msdn.microsoft.com/en-us/library/aa645740(v=vs.71).aspx
 
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