From bb25bd62e392a9aa17bccc2bf54808bd62f98ebf Mon Sep 17 00:00:00 2001
From: Ami Bar See the history section at the bottom for changes.
- The Windows system provides one .NET ThreadPool for each process. The .NET ThreadPool can contain up to 25 (by default) threads per processor. It is also stated that the operations in .NET ThreadPool should be quick to avoid suspension of the work of others who use the .NET ThreadPool. Note that several AppDomains in the same process share the same .NET ThreadPool. If you want a thread to work for a long period of time, then the .NET ThreadPool is not a good choice for you (unless you know what you are doing). Note that each asynchronous method call from the .NET Framework that begins with "Begin…" (e.g.,
There is no guarantee that a work item will be cancelled, it depends on the state
of the work item when the cancel is called and the cooperation of the work item.
- (Note the work item's state I mention here has nothing to do with the state object
+ (Note that the work item's state I mention here has nothing to do with the state object
argument provided in the
These are the possible states of a work item: (defined in the
+ This featue let the user specify a timeout for the work item in milliseconds. When the timeout expires the work item is cancelled
+ automatically. The cancel works the same as a call to Cancel with the To sample the cancel use 
Why do you need a thread pool?
@@ -96,8 +104,11 @@
+ New features added in December 2009
+
What about the .NET ThreadPool?
BeginInvoke, BeginSend, BeginReceive, etc.) uses the .NET ThreadPool to run its callback. Also note that the .NET ThreadPool
doesn't support calls to COM with single threaded apartment (STA), since the ThreadPool
@@ -397,7 +408,7 @@ SmartThreadPool.WaitAny(new IWaitableResult[] { wir1, wir2});
QueueWorkItem).WorkItemState enum)
@@ -747,6 +758,13 @@ to simplfy the initiation of a parallel task.abortExecution argument set to false (This is why the timeout is passive).SmartThreadPool.IsWorkItemCanceled which is a static property, or you can use SmartThreadPool.AbortOnWorkItemOnCancel
+which check if the current work item is cancelled and if so abort the thread (Thread.CurrentThread.Abort()).
The Smart Thread Pool is good when your work items don't do too much, but wait for events, IOs, sockets, etc. This means that the work items don't use CPU, but run for a long time. It is also good when you don't need to keep alive too many threads in the air all the time. If your work items do a short time work, then use the .NET ThreadPool. If you have a constant heavy load of work, then use Toub's thread pool and define the maximum number of threads accordingly.
@@ -1348,16 +1366,20 @@ public class PipeExample