static void Main(string[] args)
{
// Queuethe task.
ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadProc));
Console.WriteLine("Main thread does some work, thensleeps.");
// If youcomment out the Sleep, the main thread exits before
// thethread pool task runs. The thread pool usesbackground
//threads, which do not keep the application running. (This
// is asimple example of a race condition.)
Thread.Sleep(1000);
Console.WriteLine("Main thread exits.");
Console.Read();
}
// This thread procedure performs thetask.
static void ThreadProc(Object stateInfo)
{
// Nostate object was passed to QueueUserWorkItem,so
//stateInfo is null.
Console.WriteLine("Hello from the thread pool.");
}