2010-09-27 28 views
2

我们正在Beta HyperV环境中获取MVC AsyncController的TimeoutException。在本地调试时一切正常,但是当我们部署到预生产环境时,出现此错误:HyperV环境中AsyncController的TimeoutException

[TimeoutException:操作超时。] System.Web.Mvc.Async.WrappedAsyncResult`1。结束()+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); 
       } 
      } 

会是什么这个错误的一些可能的原因是什么?

回答

9

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

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

您还可以使用NoAsyncTimeout属性,但你会容易异步从未完成,并让你的Web请求无人过问行动。

+0

谢谢,这是有道理的。 – josefresno 2010-10-26 16:59:50