In ASP.NET MVC 2 async开发者_如何学Pythonhronous controllers, we can do something like this:
public class SomeController : AsyncController
{
[Blurb]
public void FooAsync()
{
this.AsyncManager.OutstandingOperations.Increment();
Task.Factory.StartNew(
() =>
{
this.AsyncManager.Parameters["result"] = new BazResult();
this.AsyncManager.OutstandingOperations.Decrement();
});
}
public ActionResult FooCompleted(ActionResult result)
{
return result;
}
}
My question is, does the action filter "Blurb" in this case execute asynchronously? In other words, is its synchronous nature automatically wrapped into an asynchronous call?
I took a look under the covers at AsyncControllerActionInvoker and it looks like it does indeed wrap them into a set of asynchronous calls and continuations. It makes a call to BeginInvokeActionMethodWithFilters which in turn sets up InvokeActionMethodFilterAsynchronously.
For those who are curious, the source is on codeplex.
精彩评论