-It appears that Task class provide us the ability to use on multiple processors in the system.
-if threads will/could be executed on multiple cores then what is so special about Task Parallelism ?
The Task
class is just a small, but important, part of TPL (Task Parallel Library). TPL is a high level abstraction, so you don't have to work with threads directly. It encapsulates and hides most of the churn you'd have to implement for any decent multi-threaded application.
Tasks don't introduce any new functionality that you couldn't implement on your own, per se (which is the core of your questions, I believe). They can be synchronous or asynchronous - when they are async, they're either using Thread
class internally or IOCP ports.
Some of the points addressed by TPL are:
- Rethrow exceptions from a child thread on the calling thread.
- Asynchronous code (launch thread -> run arbitrary code while waiting for child thread -> resume when child thread is over) looks as if it were synchronous, greatly improving readability and maintainability
- Simpler thread cancelation (using
CancellationTokenSource
)
- Parallel queries/data manipulation using PLINQ or the
Parallel
class
- Asynchronous workflows using TPL Dataflow