gpt4 book ai didi

c# - HyperV 环境中 AsyncController 的 TimeoutException

转载 作者:行者123 更新时间:2023-11-30 13:42:07 26 4
gpt4 key购买 nike

我们在 Beta HyperV 环境中的 MVC AsyncController 上收到 TimeoutException。在本地调试时一切正常,但是当我们部署到预生产环境时,我们得到这个错误:

[TimeoutException: 操作超时。] System.Web.Mvc.Async.WrappedAsyncResult`1.End() +129 System.Web.Mvc.Async.<>c_DisplayClass39.b_38(IAsyncResult asyncResult) +23 System.Web.Mvc.Async.<>c_DisplayClass33.b_2d() +125 System.Web.Mvc.Async.<>c_DisplayClass49.b_43() +452 System.Web.Mvc.Async.<>c_DisplayClass49.b_43() +452 System.Web.Mvc.Async.<>c_DisplayClass49.b_43() +452 System.Web.Mvc.Async.<>c_DisplayClass31.b_30(IAsyncResult asyncResult) +15 System.Web.Mvc.Async.<>c_DisplayClass24.b_1a() +31 System.Web.Mvc.Async.<>c_DisplayClass1f.b_1c(IAsyncResult asyncResult) +230 System.Web.Mvc.<>c_DisplayClass17.b_12(IAsyncResult asyncResult) +28 System.Web.Mvc.Async.<>c_DisplayClass4.b_3(IAsyncResult ar) +20 System.Web.Mvc.AsyncController.EndExecuteCore(IAsyncResult asyncResult) +53 System.Web.Mvc.Async.<>c_DisplayClass4.b_3(IAsyncResult ar) +20 System.Web.Mvc.<>c_DisplayClass8.b_3(IAsyncResult asyncResult) +42 System.Web.Mvc.Async.<>c_DisplayClass4.b_3(IAsyncResult ar) +20 System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar) +136

    [OutputCache(Duration = 0, NoStore = true, VaryByParam = "")]
public void IndexAsync()
{
using (var context = Repository.CreateContext().CreateUnitOfWork())
{
user = context.Users.Single(u => u.Username == User.Identity.Name);

AsyncManager.OutstandingOperations.Increment();

ThreadPool.QueueUserWorkItem(o => {
var sync = myService.DoThingsAsync(user);
sync.AsyncWaitHandle.WaitOne();
AsyncManager.OutstandingOperations.Decrement();
});
}
}

/// IndexCompleted is never called
public ActionResult IndexCompleted(string property)
{
using (var context = Repository.CreateContext().CreateUnitOfWork())
{
var user = context.Users.Single(u => u.Username == User.Identity.Name);

var model = new MyViewModel
{
ModelProperty = user.Property
};

return View("Index", model);
}
}

此错误的一些可能原因是什么?

最佳答案

这是当异步操作花费的时间超过配置的 AsyncTimeout 值(默认为 45 秒)时抛出的异常。您可以通过使用 AsyncTimeout 属性修饰 ActionMethod 来显式控制此值。例如,将异步超时设置为一整分钟:

[AsyncTimeout(60000)]
public void IndexAsync()
{
...
}

您也可以使用 NoAsyncTimeout 属性,但您很容易受到异步操作永远不会完成并使您的 Web 请求陷入困境的影响。

关于c# - HyperV 环境中 AsyncController 的 TimeoutException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3806846/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com