[C#] C#多執行緒學習(四) 多執行緒的自動管理(執行緒池)
阿新 • • 發佈:2019-02-12
Thread Pool Sample:
Queuing 10 items to Thread Pool
Queue to Thread Pool 0
Queue to Thread Pool 1
Queue to Thread Pool 2
Queue to Thread Pool 3
Queue to Thread Pool 4
Queue to Thread Pool 5 2 0 :
HashCount.Count == 0 , Thread.CurrentThread.GetHashCode() == 2
Queue to Thread Pool 6
Queue to Thread Pool
Queue to Thread Pool 8
Queue to Thread Pool 9
Waiting for Thread Pool to drain
4 1 :
HashCount.Count == 1 , Thread.CurrentThread.GetHashCode() == 4 6 2 :
HashCount.Count == 1 , Thread.CurrentThread.GetHashCode() == 6 7 3 :
HashCount.Count == 1 , Thread.CurrentThread.GetHashCode()
HashCount.Count == 1 , Thread.CurrentThread.GetHashCode() == 2 8 5 :
HashCount.Count == 2 , Thread.CurrentThread.GetHashCode() == 8 9 6 :
HashCount.Count == 2 , Thread.CurrentThread.GetHashCode() == 9 10 7 :
HashCount.Count == 2 , Thread.CurrentThread.GetHashCode() == 10 11 8
HashCount.Count == 2 , Thread.CurrentThread.GetHashCode() == 11 4 9 :
HashCount.Count == 2 , Thread.CurrentThread.GetHashCode() == 4
Setting eventX
Thread Pool has been drained (Event fired)
Load across threads
11 1 10 1 9 1 8 1 7 1 6 1 4 2 2 2