In ASP.NET MVC 2 asynchronous 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?
Action Filter is an attribute that you can apply to a controller action or an entire controller. This filter will be called before and after the action starts executing and after the action has executed. Action filters implement the IActionFilter interface that has two methods OnActionExecuting andOnActionExecuted.
The asynchronous controller enables you to write asynchronous action methods. It allows you to perform long running operation(s) without making the running thread idle. It does not mean it will take lesser time to complete the action.
Exception Filters − Exception filters are the last type of filter to run. You can use an exception filter to handle errors raised by either your controller actions or controller action results.
STEP 01 Create new MVC Application project, named as "Async". In the File menu, click New Project. In the "New Project" dialog box, under Project types, expand Visual C#, and then click "Web". In the Name box, type "Async", then click on Ok.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With