ConfigureAwait — controls where continuation runs.
1// Default — captures context2await Task.Delay(1000);3// Continues on original context (UI thread, ASP.NET context)45// ConfigureAwait(false) — no context capture6await Task.Delay(1000).ConfigureAwait(false);7// Continues on thread pool thread
When to use ConfigureAwait(false):
When NOT to use:
Example — library:
1public async Task<string> GetDataAsync() {2 // Library — no context needed3 await Task.Delay(1000).ConfigureAwait(false);4 return "data";5}
Deadlock prevention:
1// Bad — can deadlock2var result = GetDataAsync().Result;34// Good — no deadlock5var result = await GetDataAsync().ConfigureAwait(false);