我需要使用复杂的长时间工作逻辑来处理丢失的请求文件。
我可以在 Application_Error
中做到这一点,但不确定它本身是否是异步的?
如果需要 5 分钟或更长时间才能工作,此处理程序是否会一直阻止其他用户?
最佳答案
Application_Error
参与页面处理,从您加载的页面调用,因此问题是页面或处理程序本身是否异步。
是的,如果你不使用session,当然如果你不使用其他同步锁,比如mutex,或者数据库open/read/write
这是为什么呢?因为 session 锁定了完整的处理,请看这个问题/答案:
call aspx page to return an image randomly slow
ASP.NET Server does not process pages asynchronously
Trying to make Web Method Asynchronous
Web app blocked while processing another web app on sharing same session
What perfmon counters are useful for identifying ASP.NET bottlenecks?
Replacing ASP.Net's session entirely
File upload and result pooling kills ASP.NET web app
因此,为简单起见,Application_Error
只是一个静态函数调用,但连接到页面或处理程序的处理。确保页面或处理程序没有相互阻塞,一切正常。
另一方面,一个 5 分钟的处理,如果您尝试将其中的 500 个放在一起而不将它们放在查询列表中,您可能会遇到其他问题。
我只是做了一个简单的测试,将System.Threading.Thread.Sleep(20000);
放在Application_Error
上报错,继续加载其他页面,和工作。
关于asp.net - Global.asax Application_Error 是异步的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13968147/