Example

 using System; using System.Threading; namespace Samples { public class ThreadSample { public static void StartHere() { Console.WriteLine("Thread starting"); Thread.Sleep(1000); Thread t = Thread.CurrentThread; Console.WriteLine("ThreadState within StartHere: {0}", t.ThreadState); for(int i = 0; i < 10; i++) { Console.Write("."); Thread.Sleep(1000); } Console.WriteLine("\nThread finishing"); } public static void Main() { Thread t = new Thread(new ThreadStart(StartHere)); ThreadState ts = t.ThreadState; Console.WriteLine("Thread state: {0}", t.ThreadState); bool firstTime = true; t.Start(); while(ts != ThreadState.Stopped) { ThreadState tmp = t.ThreadState; if(ts != tmp) { ts = tmp; Console.WriteLine("Thread state: {0}", ts); Thread.Sleep(100); ...

Get .NET Framework Standard Library Annotated Reference, Volume 1: Base Class Library and Extended Numerics Library now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.