在ASP.NET MVC 2异步控制器中,Action Filters是否异步执行?

时间:2011-05-05 20:38:04

标签: c# asp.net-mvc-2 asynchronous

在ASP.NET MVC 2异步控制器中,我们可以这样做:

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;
    }
}

我的问题是,在这种情况下,动作过滤器“Blurb”是否异步执行?换句话说,它的同步特性是否自动包装成异步调用?

1 个答案:

答案 0 :(得分:2)

我看了 AsyncControllerActionInvoker 的封面,看起来它确实将它们包装成一组异步调用和延续。它调用 BeginInvokeActionMethodWithFilters ,然后依次设置 InvokeActionMethodFilter异步

对于那些好奇的人来说,源代码是在codeplex上。