Getting started with the TPL
The TPL consists of the types that were added to the System.Threading
and System.Threading.Tasks
namespaces in .NET Framework 4.0. The TPL provides features that make parallelism and concurrency simpler for .NET developers. There is no need to manage the ThreadPool
tasks in your code. The TPL handles thread management and automatically scales the number of active threads based on processor capability and availability.
Developers should use the TPL when they need to introduce parallelism or concurrency to their code for improved performance. However, the TPL is not the right choice for every scenario. How do you know when to choose the TPL and which TPL constructs are the best choice for each scenario?
Let’s explore a few common scenarios.
I/O-bound operations
When dealing with I/O-bound operations such as file operations, database calls, or web service calls, asynchronous programming with Task
objects and C# async
/await
operations are...