What is the difference between Task Parallel Library and await and async. What was the need to introduce await and async? I see TPL is part of C# 4.0 and await/async is part of C# 5.0 but apart from that what is the basic difference. What was the need to introduce this new keyword?
Async methods are intended to be non-blocking operations. An await expression in an async method doesn't block the current thread while the awaited task is running. Instead, the expression signs up the rest of the method as a continuation and returns control to the caller of the async method.
The Task Parallel Library (TPL) is a set of public types and APIs in the System. Threading and System. Threading. Tasks namespaces. The purpose of the TPL is to make developers more productive by simplifying the process of adding parallelism and concurrency to applications.
Await & Async was built on the Task Parallel Library (TPL) which was introduced in the . NET Framework 4. Their purpose is to enable asynchronous programming.
The purpose of TPL and the async-await features is to make the asynchronous programming almost as simple as the synchronous programming, allowing the developers to preserve the logical structure of the code even when it executes asynchronously.
The Task Parallel Library was designed for parallel programming - when you have a lot of work to do and want to split up that work among multiple threads so you can use all the CPU cores. TPL is best suited for CPU-intensive work.
Async and await are for asynchronous programming - when you have an operation (or many operations) that will complete in the future, and you want to do other things in the meantime. Async is best suited for I/O-bound work.
There is some overlap. For example, you can treat a parallel computation as an asynchronous operation so it doesn't tie up your UI thread. Also, both the TPL and async/await make use of the Task
type, though they use it in very different ways.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With