← Back to C# Course | Chapter 13: Async Programming | Lesson 4 of 6

ConfigureAwait

In this page:

  1. ConfigureAwait

ConfigureAwait

ConfigureAwait(false) tells await not to try to resume execution back on the original synchronization context (like a UI thread), which can improve performance and avoid deadlocks in library code. In console apps and modern ASP.NET Core there's no special context to return to, so it makes less practical difference there. It's mainly a library-authoring best practice rather than something application code needs everywhere.

Note: Use ConfigureAwait(false) in reusable library code that has no reason to depend on a specific UI thread.

Example: ConfigureAwait

markup
using System;
using System.Threading.Tasks;

class Program
{
    static async Task<int> LoadDataAsync()
    {
        await Task.Delay(50).ConfigureAwait(false);
        return 7;
    }

    static async Task Main(string[] args)
    {
        int value = await LoadDataAsync();
        Console.WriteLine(value);
    }
}
🔒

Chapter Quiz — Complete all 6 topics to unlock

0/6 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.