请不要在此问题上设置重复标记 - 它与“为什么会发生ThreadAbortException”无关,而是与“为什么w3wp.exe进程在ThreadAbortException后终止”有关。
假设我们有一个简单的Web应用程序,并且具有以下代码示例:
有人能检查一下这个示例并解释一下发生了什么吗?
更新:以下是与此问题相关的一些Windows事件日志。
日志 #1
未处理的异常错误导致该进程被终止。
应用程序ID:/LM/W3SVC/1/ROOT/AS
进程ID:6700
异常:System.Threading.ThreadAbortException
消息:线程正在被中止。
堆栈跟踪:在System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) at System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags) at System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)
日志 #2
假设我们有一个简单的Web应用程序,并且具有以下代码示例:
protected void Page_Load(object sender, EventArgs e)
{
Response.Redirect("http://google.com");
}
实际上意味着类似于(见Is Response.End() considered harmful?):
protected void Page_Load(object sender, EventArgs e)
{
...response write some data...
System.Threading.Thread.CurrentThread.Abort();
}
在我的机器上(Windows 10 Pro + IIS),这段代码会导致IIS进程池以0x0错误代码终止(未执行重定向)。在其他机器上(非Windows 10),此代码仅生成ThreadAborted异常,但进程继续工作(执行重定向)。有人能检查一下这个示例并解释一下发生了什么吗?
更新:以下是与此问题相关的一些Windows事件日志。
日志 #1
未处理的异常错误导致该进程被终止。
应用程序ID:/LM/W3SVC/1/ROOT/AS
进程ID:6700
异常:System.Threading.ThreadAbortException
消息:线程正在被中止。
堆栈跟踪:在System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) at System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags) at System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)
日志 #2
Faulting application name: w3wp.exe, version: 10.0.10240.16384, time stamp: 0x559f3dad
Faulting module name: KERNELBASE.dll, version: 10.0.10240.16384, time stamp: 0x559f3b2a
Exception code: 0xe0434352
Fault offset: 0x000b3e28
Faulting process id: 0x1a2c
Faulting application start time: 0x01d0e4b1b3ed01cb
Faulting application path: C:\WINDOWS\SysWOW64\inetsrv\w3wp.exe
Faulting module path: C:\WINDOWS\SYSTEM32\KERNELBASE.dll
Report Id: 23b5298d-3b36-49c7-a294-de9c864b703f
Faulting package full name:
Faulting package-relative application ID: