C# - ThreadPool vs Tasks

Viewed 67452

As some may have seen in .NET 4.0, they've added a new namespace System.Threading.Tasks which basically is what is means, a task. I've only been using it for a few days, from using ThreadPool.

Which one is more efficient and less resource consuming? (Or just better overall?)

7 Answers

ThreadPool and Task difference is very simple. To understand task you should know about the threadpool.

ThreadPool is basically help to manage and reuse the free threads. In other words a threadpool is the collection of background thread.

Simple definition of task can be:

Task work asynchronously manages the the unit of work. In easy words Task doesn’t create new threads. Instead it efficiently manages the threads of a threadpool.Tasks are executed by TaskScheduler, which queues tasks onto threads.

Another good point to consider about task is, when you use ThreadPool, you don't have any way to abort or wait on the running threads (unless you do it manually in the method of thread), but using task it is possible. Please correct me if I'm wrong

Related