﻿# 介紹好用元件：Smart Thread Pool

採用 .Net Framework 內建的 [ThreadPool](http://msdn.microsoft.com/zh-tw/library/system.threading.threadpool.aspx) 雖然也不錯用，但若真的實際用來開發時，就會發現有許多使用情境會導致程式碼過於複雜、不容易閱讀。最近發現 [Smart Thread Pool](http://www.codeplex.com/smartthreadpool) 似乎蠻不錯用的，如果你的程式有多份工作需要同步執行，而又不考慮程式執行的先後順序時，是可以考慮使用 [Smart Thread Pool](http://www.codeplex.com/smartthreadpool) 來開發多執行緒程式。

[Smart Thread Pool](http://www.codeplex.com/smartthreadpool) 元件的特性有：

-   The number of threads dynamically changes according to the workload on the threads in the pool.
-   Work items can return a value.
-   A work item can be cancelled if it hasn't been executed yet.
-   The caller thread's context is used when the work item is executed (limited).
-   Usage of minimum number of Win32 event handles, so the handle count of the application won't explode.
-   The caller can wait for multiple or all the work items to complete.
-   Work item can have a `PostExecute` callback, which is called as soon the work item is completed.
-   The state object, that accompanies the work item, can be disposed automatically.
-   Work item exceptions are sent back to the caller.
-   Work items have priority.
-   Work items group.
-   The caller can suspend the start of a thread pool and work items group.
-   Threads have priority.

若要學習 [Smart Thread Pool](http://www.codeplex.com/smartthreadpool) 要如何使用，可以參考[這篇文章](http://www.codeproject.com/KB/threads/smartthreadpool.aspx)。

**相關連結**

-   [Smart Thread Pool](http://www.codeplex.com/smartthreadpool) @CodePlex
-   [CodeProject: Smart Thread Pool](http://www.codeproject.com/KB/threads/smartthreadpool.aspx)
-   [以 C# 撰寫多執行緒 (Multi-threading) 相關學習資源整理](/post/2009/03/08/Multi-Threading-in-CSharp-Learning-Resources)
