Asynchronous Controller is blocking requests in ASP.NET MVC through jQuery

后端 未结 2 483
难免孤独
难免孤独 2020-12-01 03:23

I have just started using the AsyncController in my project to take care of some long-running reports. Seemed ideal at the time since I could kick off the report and then pe

相关标签:
2条回答
  • 2020-12-01 03:31

    Acutally the problem lays in this.HttpContext.Session, 'cause it's being locked, if you are writing anything to a session in your AsyncController, you should avoid it and using this.HttpContext.Application - this will solves the problem, I had the same problem, and try us

    0 讨论(0)
  • 2020-12-01 03:44

    There are two issues in play here. The first is that your controller is not truly asynchronous. Spinning up a ThreadPool thread to perform work generally has worse performance characteristics than just doing everything from within the action method itself, as you're still taking ThreadPool resources from ASP.NET (which just shares the CLR ThreadPool), and you're now forcing the CLR and the OS to juggle threads. See http://msdn.microsoft.com/en-us/library/ee728598.aspx#choosing_synchronous_or_asynchronous_action_methods for more information. Basically, what that link boils down to is that if you can't use I/O completion ports for your asynchronous operations, you're very unlikely to see improved performance.

    The second issue is that ASP.NET MVC takes a Session lock on all requests. Multiple requests within a single Session will always be serialized, as otherwise the user's Session could become corrupted if one controller writes to Session as another controller is trying to read it. See http://forums.asp.net/t/1501623.aspx for context and a workaround. MVC 2 Futures has a way of disabling this lock; it may also be included in MVC 3 proper. See https://blogs.msdn.com/b/rickandy/archive/2009/12/17/session-less-mvc-controller.aspx for more information on this.

    0 讨论(0)
提交回复
热议问题