Why can .Result or .Wait() deadlock, and what's the fix?
Short answer
In a single-threaded context the blocked thread waits for a continuation that needs that same thread — neither proceeds. Fix by awaiting all the way down.
Advertisement
AModel answer
In a single-threaded context the blocked thread waits for a continuation that needs that same thread — neither proceeds. Fix by awaiting all the way down.
// risky: var d = LoadAsync().Result;
var d = await LoadAsync();Real-world example
A legacy MVC action blocking on an async call hangs under load until made async end-to-end.