Mega Code Archive

 
Categories / C# by API / System Threading
 

Thread IsAlive

using System; using System.Threading; public class ThreadState {     static void WorkerFunction() {         for (int i = 1; i < 50000; i++) {             Console.WriteLine("Worker: " + Thread.CurrentThread.ThreadState);         }     }     static void Main() {         string ThreadState;         Thread t = new Thread(new ThreadStart(WorkerFunction));         t.Start();         while (t.IsAlive) {             Console.WriteLine("Still waiting. I'm going back to sleep.");             Thread.Sleep(200);         }         Console.WriteLine(t.ThreadState);     } }