For ASP.NET Classic (.NET Framework), there is a special AspNetSynchronizationContext
, the continuation will post back to the original context thread.
ASP.NET Core there isn’t one. If you inspect SynchronizationContext.Current
you’ll find that it’s set to null
. As such, a continuation is free to use what ever thread it chooses, and will suffer no classic deadlocks in that respect
Update
Some great corrections from @StephenCleary in the comments
Minor correction : on classic ASP.NET, the SynchronizationContext
represents the request context, not a specific thread.
The method may resume on any thread pool thread after the await
.
The deadlock occurs because there is a lock as part of that request
context to ensure that only one thread at a time may be in the
request context.
So, when the async method is ready to resume, a thread pool thread
is taken which enters the request context and tries to take that
lock. If there's another thread blocked on that task in the context, the lock is already taken and a deadlock will occur