2010-09-27 73 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