Are there any scenario where Tasks should not be used? Are there any scenario where Tasks should not be used? multithreading multithreading

Are there any scenario where Tasks should not be used?


Since Tasks use the underlying ThreadPool (unless marked as long running), it's a bad idea to use them whenever using a ThreadPool is not advised e.g.

  • long I/O operations that clog the task queue and prevent other tasks from being executed.
  • doing operations that require thread identity such as setting affinity.


This is gone into detail over here:Should I notice a difference in using Task vs Threads in .Net 4.0?

This biggest difference is that the TaskFactory uses thread pooling, so if you have a lot of tasks they may not start immediately. They have to wait for a free thread to run. In most cases this is acceptable..

Threads will run instantly as soon as .Start() is called, hardware permitting.

Assuming Thread pooling is okay, Tasks offer many benefits including cancellation, ContinueWith, OnSuccess, OnError, Exception aggregation, and WaitAll to name a few off the top of my head.