Saturday, February 4, 2012

What is thread join?

Stops of prevents the calling thread until a called thread terminates, and side by side continuing to perform standard COM and SendMessage pumping.


Syntax of this method :


// create a new thread object from thread class
Thread threadToJoin  =  new Thread(threadmethod); 


//Thread have come to running state.
threadToJoin.Start();   


 // Wait for foreground thread to end.
threadToJoin.Join()
^
 |   ____ so this threadToJoin thread will wait, until other threads are terminated.


Example : Suppose you are cooking something, and in between you need something to finish cooking, so you send your servant to get that, so you will call your cooking thread .join to wait till the servant thread not finished/ servant does not come with required item, and when servant arrives with the item servant thread terminates and your thread can continue.
               
void threadmethod()
{
    //method body
}









Versions of Thread Join Method:


Join                       ->   Blocks the calling thread until a thread terminates, while continuing to perform          
                                      other task
Join(int)               ->   Blocks the calling thread until a thread terminates or the specified time elapses, 
                                      while continuing to perform other task


Join(timeSpan)  ->    Blocks the calling thread until a thread terminates or the specified time elapses, 
                                      while continuing to perform other task





No comments:

Post a Comment

Live

Your Ad Here