Mega Code Archive

 
Categories / C# Book / 10 Thread
 

0632 Join a Thread

Once started, a thread's IsAlive property returns true, until the point where the thread ends. A thread ends when the delegate passed to the Thread's constructor finishes executing. Once ended, a thread cannot restart. You can wait for another thread to end by calling its Join method. Here's an example: using System; using System.Threading; class ThreadTest { static void Main() { Thread t = new Thread(Go); t.Start(); t.Join(); Console.WriteLine("Thread t has ended!"); } static void Go() { for (int i = 0; i < 10; i++) Console.Write("y"); } } The output: yyyyyyyyyyThread t has ended!