The only reason why I wouldn't use the ThreadPool
for cheap multithreading is if I need to…
- interract with the method running (e.g., to kill it)
- run code on a STA thread (this happened to me)
- keep the thread alive after my application has died (
ThreadPool
threads are background threads)
- in case I need to change the priority of the Thread. We can not change priority of threads in ThreadPool which is by default Normal.
P.S.: The MSDN article "The Managed Thread Pool" contains a section titled, "When Not to Use Thread Pool Threads", with a very similar but slightly more complete list of possible reasons for not using the thread pool.
There are lots of reasons why you would need to skip the ThreadPool
, but if you don't know them then the ThreadPool
should be good enough for you.
Alternatively, look at the new Parallel Extensions Framework, which has some neat stuff in there that may suit your needs without having to use the ThreadPool
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…