I was working on a presentation and thought the following should fail since the ActionResult isn\'t being returned on the right context. I\'ve load tested it with VS and got no
It appears because the Controller captures the Context whereas using System.Web.HttpContext
is live access to what is part of the synchronization context.
If we look at the ASP.NET MVC5 sources we can see that the ControllerBase
class that all controllers inherit from has its own ControllerContext
which is built from the RequestContext
.
I would assume this means that while the synchronization context is lost after a ConfigureAwait(false);
the state of the Controller
in which the continuation is happening still has access to the state of the control from before the continuation via the closure.
Outside of the Controller
we don't have access to this ControllerContext
so we have to use the live System.Web.HttpContext
which has all the caveats with ConfigureAwait(false);
.