速记 线程池

早上起的得早,搂了一眼线程池的内容速记下来。
        public static void Main()
        {
            // Queue the task.
            ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadProc));
            ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadProc2));
            Console.WriteLine("Main thread does some work, then sleeps.");
            // If you comment out the Sleep, the main thread exits before
            // the thread pool task runs.  The thread pool uses background
            // threads, which do not keep the application running.  (This
            // is a simple example of a race condition.)
            Thread.Sleep(10000);
            Console.WriteLine("Main thread exits.");
            Console.ReadLine();
        }
        // This thread procedure performs the task.
        static void ThreadProc(Object stateInfo)
        {
            // No state object was passed to QueueUserWorkItem, so
            // stateInfo is null.
            Thread.Sleep(5000);
            Console.WriteLine("1111111");
        }
        static void ThreadProc2(Object stateInfo)
        {
            // No state object was passed to QueueUserWorkItem, so
            // stateInfo is null.
            Thread.Sleep(3000);
            Console.WriteLine("222222.");
        }
 
Output:
Main thread does some work, then sleeps.
222222.
1111111
Main thread exits.
请使用浏览器的分享功能分享到微信等