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