參考:
http://msdn.microsoft.com/zh-cn/library/system.threading.threadpool(VS.80).aspx
http://www.codeproject.com/KB/threads/threadtests.aspx
http://www.codeproject.com/KB/threads/smartthreadpool.aspx
http://blog.zhaojie.me/2009/07/thread-pool-1-the-goal-and-the-clr-thread-pool.html (老趙的淺談線程池上中下三篇)
Jeffrey Richter <<CLR via C#>> 3rd Edition
先大概看一下控制台應用程序的Main方法的主要代碼:
001
static bool done = false;
002
static decimal count2 = 0;
003
static int threadDone = 0;//標志啟用線程數?
004
static System.Timers.Timer timer = new System.Timers.Timer(1000);
005
006
static decimal[] threadPoolCounters = new decimal[10];
007
static Thread[] threads = new Thread[10];
008
static System.Timers.Timer[] threadTimers = new System.Timers.Timer[10];
009
010
static void Main(string[] args)
011
{
012
timer.Stop();
013
/*當 AutoReset 設置為 false 時,Timer 只在第一個 Interval 過後引發一次 Elapsed 事件。
014
若要保持以 Interval 時間間隔引發 Elapsed 事件,請將 AutoReset 設置為 true。*/
015
timer.AutoReset = false;
016
timer.Elapsed += new ElapsedEventHandler(OnTimerEvent);//當timer.Start()時,觸發事件
017
decimal total = 0;
018
019
// raw test
020
decimal count1 = SingleThreadTest();//單一線程,一跑到底
021
Console.WriteLine("Single thread count = "