Why Async Deadlocks Hit WPF/WinForms but Spare Console Apps Explained
Blocking on async tasks using .Result or .Wait() can cause deadlocks in UI applications like WPF and WinForms, but the same code runs without issue in console applications. The difference lies in the synchronization context: UI frameworks use a single-threaded context that marshals continuations back to the main thread. When that main thread is blocked waiting for the task, and the task's continuation also needs that same thread, a deadlock occurs. Console apps lack this single-threaded synchronization context, so continuations can resume on any available thread pool thread. Using ConfigureAwait(false) instructs the awaiter to skip capturing the synchronization context, allowing continuations to run on a thread pool thread and breaking the deadlock cycle.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.


Discussion (0)
Log in to join the discussion and vote.
Log in