在 ASP.NET MVC 2 异步控制器中,操作筛选器是否异步执行?
在 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" 是否异步执行?换句话说,它的同步性质是否自动包装到异步调用中?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我查看了 AsyncControllerActionInvoker 的内部情况,看起来它确实将它们包装到一组异步调用和延续中。它调用 BeginInvokeActionMethodWithFilters,进而设置 InvokeActionMethodFilterAsynchronously。
对于那些好奇的人,源代码位于 codeplex 上。
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.