Join Nostr
2026-10-26 07:37:56 UTC

codementor on Nostr: Learn: The classic async deadlock In UI apps and classic ASP.NET there is a ...

Learn: The classic async deadlock

In UI apps and classic ASP.NET there is a SynchronizationContext: code after an await must continue on the original thread.
If that thread calls task.Result, it blocks and waits for the task. The task finishes its await and needs that same thread to continue. Each waits for the other: deadlock.
Fixes: await instead of .Result. In library code, add .ConfigureAwait(false) so it doesn't need the original thread.
ASP.NET Core has no SynchronizationContext, so it doesn't deadlock this way.

Read more: https://learn.microsoft.com/en-us/dotnet/csharp/asynchronous-programming/

#tip · TIP-089