ThreadAbortException是一个特殊的异常,它通常在取消正在运行的线程时抛出。当在Asp.Net应用程序中发生这个异常时,它会使应用程序变得不稳定并在日志中留下痕迹。
以下是解决这个问题的一些方法:
在
例如,你可能需要在try-catch块中将ThreadAbortException更改为System.Exception。
try
{
// some code here
}
catch (ThreadAbortException e)
{
// handle the exception here
}
改为:
try
{
// some code here
}
catch (System.Exception e)
{
if(!(e is ThreadAbortException))
// handle the exception here
}
这样做将捕获除ThreadAbortException之外的其他所有异常,并将它们记录到日志中。
当应用程序发生未处理的异常时,应该让它抛出并终止处理。然后可以在Global.asax文件的Application_Error事件中记录这个异常,但不要重新抛出它。
protected void Application_Error(object sender, EventArgs e)
{