为什么我得到“线程被中止”在asp.net? [英] Why am i getting "Thread was being aborted" in asp.net?

查看:105
本文介绍了为什么我得到“线程被中止”在asp.net?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道为什么会发生这种情况,我从来没有明确地中止线程,所以这是一个惊喜。但是我记录了异常,我看到:


System.Threading.ThreadAbortException - 线程正在中止。


似乎发生在调用 System.Threading.WaitHandle.WaitOne 中。我不知道这个异常有多远。我不认为我的线程终止,因为我抓住日志并吞下错误。



有谁知道为什么我得到这些错误?也许这是当我强力终止我的服务器或要求它重新启动?如果不是那么可能导致他们?

解决方案

如果您在Application_Start中生成线程,它们仍将在应用程序池的AppDomain。如果应用程序空闲一段时间(意味着没有请求进入)或某些其他条件得到满足,ASP.NET将回收整个应用程序域。当这种情况发生时,您从AppDomain启动的任何线程(包括Application_Start中的线程)将被中止。



在此问题中,更多应用程序池和回收:什么是Appdomain回收



如果您尝试在IIS / ASP.NET中运行长时间运行的过程,那么简短的答案通常是不要。这就是Windows服务。


I am not sure why this happens and I never explicitly abort threads, so it's a bit of a surprise. But I log Exceptions and I am seeing:

System.Threading.ThreadAbortException - Thread was being aborted.

It appears to happen in a call to System.Threading.WaitHandle.WaitOne. I am not sure how far this Exception goes. I don't think my threads ever terminate because I catch log and swallow the error.

Does anyone know why I'm getting these errors? Perhaps it's when I am forcefully terminating my server or asking it to reboot? If it isn't then what might be causing them?

解决方案

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

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.

这篇关于为什么我得到“线程被中止”在asp.net?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆