C#線程池操作演示源碼

把開發過程中經常用到的一些代碼段做個備份,下面代碼內容是關於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));

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章