Skip to content

Task based Asynchronous Pattern TAP

Context: The Task‑based Asynchronous Pattern (TAP) is the recommended asynchronous pattern in .NET. It uses Task and Task<T> to represent ongoing operations.

Asynchronous programming allows your application to continue executing other work while waiting for long‑running operations (I/O, network calls, database queries). In C#, the async and await keywords make writing asynchronous code almost as simple as synchronous code, without blocking threads.

Why use async/await?

  • Responsiveness: UI applications remain responsive during long operations.
  • Scalability: Server applications handle more requests by freeing threads during I/O.
  • Simplicity: Write asynchronous code that looks like synchronous code.

How to start: Add async to a method, then use await on tasks. The method must return Task, Task<T>, or void (only for event handlers).

// Synchronous version (blocks thread)
string data = DownloadString(url);
// Asynchronous version (does not block)
string data = await DownloadStringAsync(url);

A method following TAP returns a Task or Task<TResult> and is typically named with an Async suffix.

public Task<string> DownloadStringAsync(string url);
public Task<int> GetUserCountAsync();

ASP.NET Core controllers: All controller actions can be async, improving scalability by not blocking threads during database calls.

Official documentation: