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

Please tell me how to run 2 threads simultaneously within a process.


Thanks in advance
Posted
Comments
Prerak Patel 29-Jun-11 2:06am    
Not clear.

 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 29-Jun-11 2:16am    
Useful -- my 5. Please see my post for a general answer.
--SA
There are generally three ways:


  1. System.Threading.Thread (see its constructor and the method Run); see http://msdn.microsoft.com/en-us/library/system.threading.thread.aspx[^];
  2. Using thread from the thread pool, see http://msdn.microsoft.com/en-us/library/3dasc8as(v=VS.100).aspx[^];
  3. Using System.ComponentModel.BackgroundWorker; see http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx[^].


In all three cases you run your code in a separate thread; no matter how the thread is obtained, they are all just equivalent threads; you can use System.Threading.Thread.CurrentThread and other properties and methods of the class System.Threading.Thread.

—SA
 
Share this answer
 
Comments
Prerak Patel 29-Jun-11 2:19am    
Better explained. Have a 5.
Sergey Alexandrovich Kryukov 29-Jun-11 2:51am    
Thank you, Prerak.
--SA
Timberbird 29-Jun-11 2:45am    
Never used BackgroundWorker; thanks
Sergey Alexandrovich Kryukov 29-Jun-11 2:52am    
You are welcome. I never use BackgroundWorker, too. This is not for real men. :-)
--SA
Morl99 29-Jun-11 3:52am    
Great answer for a very general question, my 5 for your effort.
Use Thread[^] class. You can find more about using threads here[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 29-Jun-11 2:16am    
There are more to it -- please see my answer.
--SA

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