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

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

问题描述

我不知道为什么会这样,我从来没有明确终止线程,所以这是一个有点意外。但我记录异常,我看到:

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 - 线程已被中止

System.Threading.ThreadAbortException - Thread was being aborted.

它出现在调用发生在 System.Threading.WaitHandle.WaitOne 。我不知道这个异常走多远。我不认为我曾经线程终止,因为我赶上日志和吞下错误。

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?

推荐答案

如果你的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.

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

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