1. 程式人生 > >C#線程池操作演示源碼

C#線程池操作演示源碼

call sage ring str message 線程池 static lba adl

把開發過程中經常用到的一些代碼段做個備份,下面代碼內容是關於C#線程池操作演示的代碼。

static void Main(string[] args)
{
ThreadPool.SetMaxThreads(1000, 1000);
for (int i = 0; i < 10;i )
{
ThreadPool.QueueUserWorkItem(new WaitCallback(ShowMessage), string.Format("當前編號{0}",i));
}
Console.ReadLine();

}
static void ShowMessage(object x)
{
string current = string.Format("當前線程id為{0}", System.

Threading.Thread.CurrentThread.ManagedThreadId);
System.Threading.Thread.Sleep(1000);
Console.WriteLine(string.Format("{0},輸入為{1}", current, x));

}

C#線程池操作演示源碼