The task-based asynchronous pattern
The task-based asynchronous pattern (TAP) is a pattern that's used to represent arbitrary asynchronous operations. The concept of this pattern is to represent asynchronous operations in a method and combine the status of the operation and the API that is used to interact with these operators for them to become a single object. The objects are the Task
and Task<TResult>
types in the System.Threading.Tasks
namespace.
Introducing the Task and Task<TResult> classes
The Task
and Task<TResult>
classes were announced in .NET Framework 4.0 in order to represent an asynchronous operation. It uses threads that are stored in the thread pool but offers the flexibility of how the task is created. We use the Task
class when we need to run a method as a task but don't need the return value; otherwise, we use the Task<TResult>
class when we need to get the return value.
Note
We can find a complete reference, including methods and properties, inside...