Threads Joining : Thread Join : Thread C# Examples


C# Examples » Thread » Thread Join »

 

Threads Joining









    
using  System;
using  System.Threading;

class  Util
{
        public  void  DoSleep()
        {
                Console.WriteLine("Sleepping  {0}  seconds",  5);
                Thread.Sleep(5  *  1000);
        }
        
        public  static  Thread  Sleep()
        {
                Util  ts  =  new  Util();
                Thread  thread  =  new  Thread(new  ThreadStart(ts.DoSleep));
                thread.Start();
                return(thread);
        }
}

class  MainClass
{
        public  static  void  Main()
        {
                Thread  thread  =  Util.Sleep();
                
                Console.WriteLine("Waiting  for  thread  to  join");
                thread.Join();
                Console.WriteLine("Thread  Joined");
        }
}
    
   
  
   



Output

Sleepping 5 seconds
Waiting for thread to join
Thread Joined


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Thread
» Thread Join