March 2004
Intermediate to advanced
560 pages
26h 47m
English
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); ...Read now
Unlock full access