23 Oct 2025
What does .ConfigureAwait(false) do in C#?
.ConfigureAwait(false) is a method on the Task class in C#, introduced in .NET Framework 4.6 and later versions of the framework, as well as in .NET Core 1.0 and later versions of the framework.
When you call .Wait() or .Result on a task, it blocks the current thread until the task is completed. This can cause issues if the current thread is an UI thread (in WPF or WinForms applications), because blocking the UI thread can lead to a frozen application.
The issue with .Wait() and .Result is that they do not release any locks held by the calling thread, nor do they allow other tasks or threads to run. This can lead to deadlocks if multiple threads are waiting for each other.
That's where .ConfigureAwait(false) comes in.
When you call .Wait(), .Result, or GetAwaiter().ContinueOnCapturedContext() on a task that has .ConfigureAwait(false), it does not block the current thread. Instead, it configures the awaiter to run its continuation (the code after .Wait() or .Result) on any context, not just the captured context of the original call.
In other words, .ConfigureAwait(false) tells the framework to continue running the task's continuation on a background thread instead of on the UI thread. This allows your application to remain responsive and avoid deadlocks.
Here is an example:
public void DoSomething()
{
var task = Task.Run(() => { /* do something */ });
// Without ConfigureAwait(false)
task.Wait(); // blocks current thread
// With ConfigureAwait(false)
task.ConfigureAwait(false).Wait(); // does not block current thread
}
Note that using .ConfigureAwait(false) does not improve performance. It only affects the behavior of asynchronous code in relation to blocking calls like .Wait() and .Result. If you are already using async/await correctly (i.e., avoiding blocking calls), then .ConfigureAwait(false) will have no effect on your application's performance.
It is worth noting that when using a library like async/await, it is usually sufficient to use the default behavior, which means calling .Wait() or .Result without .ConfigureAwait(false). However, if you need fine-grained control over how your asynchronous code behaves (for example, in high-performance applications), then understanding and correctly applying .ConfigureAwait(false) can be crucial.
Every now and then I have to prioritize work, life or other matters but we'll soon continue with the ML Basics on YouTube
Kind regards, Auguste @ kiss-code
I continuously build, learn and experiment with innovative technology. Allow me to share what I learn, with you.