Tom*_*Tom 13 asp.net asp.net-mvc asp.net-4.0 async-await asp.net-mvc-3
我需要调用一个Task从内部返回a的方法
public override void OnActionExecuting(ActionExecutingContext filterContext)
Run Code Online (Sandbox Code Playgroud)
它不会让我使这个方法异步它抛出以下
在异步操作仍处于挂起状态时完成异步模块或处理程序.
并在打电话时
entityStorage.GetCurrentUser().Result
Run Code Online (Sandbox Code Playgroud)
我陷入僵局.我怎么能避免这个?
我一直在玩它想出类似的东西
entityStorage.GetCurrentUser().Result.ConfigureAwait(false).GetAwaiter().GetResult();
Run Code Online (Sandbox Code Playgroud)
但这不起作用.我该怎么做?我的解决方案需要使用ASP.NET 4和Async Targetting Pack,我不能使用ASP.NET 4.5作为部署到Azure.
由于await只是编译器为您重写延续的语法糖,因此最“直接”的路径是采用await后面的任何代码并将其设为ContinueWith调用。
所以,像这样:
entityStorage.GetCurrentUser().ContinueWith(t =>
{
// do your other stuff here
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8665 次 |
| 最近记录: |