ThreadPool is a static class. If I want let the ThreadPool to perform
different type of tasks, they will interfere with each other. Is there a
better solution?
As Arne says, the threads in the .NET ThreadPool class will, for the most
part, interfere with each to no greater degree than threads from multiple
thread pool classes. Theoretically, the issues using ThreadPool would be:
-- Reaching the maximum number of active threads for the pool. In the
current versions of .NET, this maximum number is very high (if I recall
correctly, 250 threads per CPU core). You likely run into lots of other
problems related only to the number of current threads long before you max
out the thread pool.
-- Throttled activations of threads. The ThreadPool class will only
add one new thread after a certain delay of having a non-empty task queue
(half a second, if I recall correctly). Over a period of time, the
ThreadPool will eventually stabilize and this won't be an issue, but it
might delay throughput initially.
In practice, neither of these issues are usually an actual problem,
assuming your workload is designed sensibly and fits the hardware
configuration well.
All that said, if you still feel a need to have a thread pool class with
more flexibility than the built-in one, you might check out Jon Skeet's
custom thread pool class, found in his "MiscUtil" library:
http://www.yoda.arachsys.com/csharp/miscutil/
Pete