1. 程式人生 > >c#多執行緒,原理和常用方法

c#多執行緒,原理和常用方法

using System;
using System.Text;
using System.Threading;

namespace 多執行緒
{
    
publicclass Example
    {
        
publicstaticvoid Main()
        {
            
// Queue the task.            ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadProc));

            Console.WriteLine(
"Main thread does some work, then sleeps.
");
          
            Thread.Sleep(
1000);

            Console.WriteLine(
"Main thread exits.");
        }

        
staticvoid ThreadProc(Object stateInfo)
        {
            
// No state object was passed to QueueUserWorkItem, 
            
// so stateInfo is null.            Console.WriteLine("Hello from the thread pool.
");
        }
    }
}