Back to results for “Asynchronous Programming”
C# › Asynchronous Programming

Why does calling .Result or .Wait() on a Task risk causing a deadlock, particularly in ASP.NET (non-Core) or UI applications?

Intermediate

Answer

Synchronously blocking on a Task (.Result/.Wait()) while the current SynchronizationContext only allows one thread to run at a time can deadlock: the blocked thread waits for the async operation to complete, but that operation's continuation is trying to resume on the SAME captured context, which is stuck waiting — neither can proceed.
// Risky: can deadlock in ASP.NET / WinForms / WPF
string result = FetchDataAsync().Result;

// Safe: properly asynchronous all the way up
string result2 = await FetchDataAsync();
Real-world example Debugging a mysterious application hang traced back to a synchronous .Result call inside a legacy ASP.NET MVC controller action.

Common follow-ups: Why doesn't this same deadlock risk apply to ASP.NET Core or console applications by default?