Member-only story

What’s the fuss about ConfigureAwait in asynchronous C#

Unveiling the Hidden Mechanics of .NET and C#

Anthony Trad
5 min readApr 4, 2023
Meme

Introduction

I admit, asynchronous and parallel programming in C# is hard. You can do the same thing in so many different ways… One can think the end result is similar, it might be hugely different under the hood which gets in your way most of the time.

“Use this here and don’t use that”. You hear that alot without knowing why and where, and you can’t even know that they are right or wrong!

Here, I am uncovering one of the most commonly misunderstood things in C# which is ConfigureAwait :

What’s ConfigureAwait?

ConfigureAwait in C# is like telling your async code whether it should keep running on the same thread that called it, or switch to another thread in the background. Let’s consider this example:

public async Task InsertClient(User u, CancellationToken token)
{
var client = u.GetInnerClient(); // Operation (1)

await Api.PutAsync(client, token); // Operation (2)

NotifyUser(u); // Operation (3)
}

Here’s what we’re doing:

  1. We’re receiving a User, mapping it somehow to a Client. (Operation 1)

--

--

Anthony Trad
Anthony Trad

Written by Anthony Trad

Senior Software Engineer focused on .NET and the Cloud. Reconsidering major principles and patterns, ideas are my own.

Responses (2)