且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么我会收到"线程已被中止"在asp.net?

更新时间:2021-08-19 22:49:59

如果你的Application_Start生成线程,他们仍然会在应用程序池的AppDomain中执行。如果应用程序是空闲一段时间(即没有请求进来),或某些其他条件都满足时,ASP.NET将回收应用程序域整。当发生这种情况,您从该AppDomain中,包括那些从开始的Application_Start任何线程,将被中止。

If you spawn threads in Application_Start, they will still be executing in the application pool's AppDomain. If an application is idle for some time (meaning that no requests are coming in), or certain other conditions are met, ASP.NET will recycle the entire appdomain. When that happens, any threads that you started from that AppDomain, including those from Application_Start, will be aborted.

在这个问题很多更多的应用程序池和回收>

Lots more on application pools and recycling in this question: What exactly is Appdomain recycling

如果您尝试运行IIS / ASP.NET中的一个长期运行的过程中,简短的回答通常是不要。这就是Windows服务是。

If you are trying to run a long-running process within IIS/ASP.NET, the short answer is usually "Don't". That's what Windows Services are for.