System.Threading.ThreadAbortException: 正在中止线程
最近做的系统中老出现的一些问题不太明白,在使用 Response.End、Response.Redirect 或 Server.Transfer 时出现 ThreadAbortException ,本来系统是没有问题的,在保存数据时也可以正常,本来使用try-catch
##[操作记录]:2007-11-23 9:25:12
System.Threading.ThreadAbortException: 正在中止线程。
在 System.Threading.Thread.AbortInternal()
在 System.Threading.Thread.Abort(Object stateInfo)
在 System.Web.HttpResponse.End()
在 System.Web.HttpResponse.Redirect(String url, Boolean endResponse)
在 System.Web.HttpResponse.Redirect(String url)
在 rsdl.ind_arcAddup.BtnSaveExit_Click(Object sender, EventArgs e) 位置 D:\rsdl\app\arc\ind_arcAddup.aspx.vb:行号 525
代码如下:
Protected
Sub BtnSaveExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnSaveExit.Click
'保存退出
If LtlarcID.Text <> "" Then
If reconredTextBox.Text <> LtlReconred.Text Then
Pf.ShowMessage(Me, "您修改了档案号!无法保存!如果你必须修改档案号,请与管理员联系!")
Exit Sub
End If
End If
vDate()
If IIf(LtlarcID.Text = "", 0, LtlarcID.Text) = 0 Then
HisArcActLog("增加用户档案信息", "档案表", "档案号" & reconredTextBox.Text & "," & nameTextBox.Text, 0)
Else
HisArcActLog("修改用户档案信息", "档案表", "档案号" & reconredTextBox.Text & "," & nameTextBox.Text, LtlarcID.Text)
End If
Try
SaveData()
Response.Redirect("ind_arcManage.aspx") '此行号为 525
Catch ex As Exception
LogError(ex.ToString, "~/ErrLog.txt")
ShowMessage(Me, "该档案号已经在使用,或信息填写错误,无法保存!\n\n如果该档案号是录入错误而删除,请与管理员联系清空该档案号!")
End Try
End Sub
症状
如果使用
Response.End、
Response.Redirect
或
Server.Transfer
方法,将出现
ThreadAbortException
异常。您可以使用
try-catch
语句捕获此异常。
原因
Response.End
方法终止页的执行,并将此执行切换到应用程序的事件管线中的
Application_EndRequest
事件。不执行
Response.End
后面的代码行。
此问题出现在
Response.Redirect
和
Server.Transfer
方法中,因为这两种方法均在内部调用
Response.End。
此问题出现在
解决方案
要解决此问题,请使用下列方法之一:
对于 | |
对于 如果使用此替代方法,将执行 | |
| 对于 |