static void Main(string[] args) { Console.WriteLine("***** Fun with the CLR Thread Pool *****\n"); Console.WriteLine("Main thread started. ThreadID = {0}", Thread.CurrentThread.ManagedThreadId); Printer p = new Printer(); WaitCallback workItem = new WaitCallback(PrintTheNumbers); // Queue the method ten times. for (int i = 0; i < 10; i++) { ThreadPool.QueueUserWorkItem(workItem, p); } Console.WriteLine("All tasks queued"); Console.ReadLine(); }
private static void PrintNumbers(object state) { Printer task = (Printer)state; task.PrintNumbers(); }