ConfigureAwait & Synchronization Context
Understand SynchronizationContext, use ConfigureAwait(false) in library code, and avoid deadlocks in async flows.
What Is SynchronizationContext?
SynchronizationContext controls how continuation code after an await is scheduled. In UI apps (WPF, WinForms), it ensures UI updates happen on the UI thread. In ASP.NET Core, there is no synchronization context (it was removed). Understanding this is key to writing correct async code.
How ConfigureAwait Works
.ConfigureAwait(false) tells the awaiter NOT to capture and resume on the current SynchronizationContext. The continuation runs on any available thread pool thread instead.
// Default: captures context (resumes on original context)
var data = await FetchDataAsync();
UpdateUI(data); // runs on UI thread — correct for UI apps
// ConfigureAwait(false): doesn't capture context
var data2 = await FetchDataAsync().ConfigureAwait(false);
// Runs on any thread — DON'T access UI thread-only objects hereAll lessons in this course
- IAsyncEnumerable & await foreach
- System.Threading.Channels
- ValueTask & Avoiding Allocations
- ConfigureAwait & Synchronization Context