加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

System.Threading.ThreadAbortException: 正在中止线程

(2012-09-10 10:17:32)
标签:

it

正在中止线程

threadabortexception

threading

response.end

分类: 服务器代码相关

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

代码如下:
http://www.web3.cn/Images/OutliningIndicators/ExpandedBlockStart.gif正在中止线程" TITLE="System.Threading.ThreadAbortException: 正在中止线程" />Protected Sub BtnSaveExit_Click(ByVal sender As ObjectByVal As System.EventArgs) Handles BtnSaveExit.Click
http://www.web3.cn/Images/OutliningIndicators/InBlock.gif正在中止线程" TITLE="System.Threading.ThreadAbortException: 正在中止线程" /> '保存退出
http://www.web3.cn/Images/OutliningIndicators/InBlock.gif正在中止线程" TITLE="System.Threading.ThreadAbortException: 正在中止线程" />
 If LtlarcID.Text <> "" Then
http://www.web3.cn/Images/OutliningIndicators/InBlock.gif正在中止线程" TITLE="System.Threading.ThreadAbortException: 正在中止线程" />
http://www.web3.cn/Images/OutliningIndicators/InBlock.gif正在中止线程" TITLE="System.Threading.ThreadAbortException: 正在中止线程" /> If reconredTextBox.Text <> LtlReconred.Text Then
http://www.web3.cn/Images/OutliningIndicators/InBlock.gif正在中止线程" TITLE="System.Threading.ThreadAbortException: 正在中止线程" /> Pf.ShowMessage(Me"您修改了档案号!无法保存!如果你必须修改档案号,请与管理员联系!")
http://www.web3.cn/Images/OutliningIndicators/InBlock.gif正在中止线程" TITLE="System.Threading.ThreadAbortException: 正在中止线程" /> Exit Sub
http://www.web3.cn/Images/OutliningIndicators/InBlock.gif正在中止线程" TITLE="System.Threading.ThreadAbortException: 正在中止线程" /> End If
http://www.web3.cn/Images/OutliningIndicators/InBlock.gif正在中止线程" TITLE="System.Threading.ThreadAbortException: 正在中止线程" />
http://www.web3.cn/Images/OutliningIndicators/InBlock.gif正在中止线程" TITLE="System.Threading.ThreadAbortException: 正在中止线程" /> End If
http://www.web3.cn/Images/OutliningIndicators/InBlock.gif正在中止线程" TITLE="System.Threading.ThreadAbortException: 正在中止线程" /> vDate()
http://www.web3.cn/Images/OutliningIndicators/InBlock.gif正在中止线程" TITLE="System.Threading.ThreadAbortException: 正在中止线程" /> If IIf(LtlarcID.Text "", 0, LtlarcID.Text) Then
http://www.web3.cn/Images/OutliningIndicators/InBlock.gif正在中止线程" TITLE="System.Threading.ThreadAbortException: 正在中止线程" /> HisArcActLog("增加用户档案信息", "档案表", "档案号" reconredTextBox.Text "," nameTextBox.Text, 0)
http://www.web3.cn/Images/OutliningIndicators/InBlock.gif正在中止线程" TITLE="System.Threading.ThreadAbortException: 正在中止线程" /> Else
http://www.web3.cn/Images/OutliningIndicators/InBlock.gif正在中止线程" TITLE="System.Threading.ThreadAbortException: 正在中止线程" /> HisArcActLog("修改用户档案信息", "档案表", "档案号" reconredTextBox.Text "," nameTextBox.Text, LtlarcID.Text)
http://www.web3.cn/Images/OutliningIndicators/InBlock.gif正在中止线程" TITLE="System.Threading.ThreadAbortException: 正在中止线程" /> End If
http://www.web3.cn/Images/OutliningIndicators/InBlock.gif正在中止线程" TITLE="System.Threading.ThreadAbortException: 正在中止线程" />
http://www.web3.cn/Images/OutliningIndicators/InBlock.gif正在中止线程" TITLE="System.Threading.ThreadAbortException: 正在中止线程" /> Try
http://www.web3.cn/Images/OutliningIndicators/InBlock.gif正在中止线程" TITLE="System.Threading.ThreadAbortException: 正在中止线程" /> SaveData()
http://www.web3.cn/Images/OutliningIndicators/InBlock.gif正在中止线程" TITLE="System.Threading.ThreadAbortException: 正在中止线程" /> Response.Redirect("ind_arcManage.aspx") '此行号为 525 
http://www.web3.cn/Images/OutliningIndicators/InBlock.gif正在中止线程" TITLE="System.Threading.ThreadAbortException: 正在中止线程" />
 Catch ex As Exception
http://www.web3.cn/Images/OutliningIndicators/InBlock.gif正在中止线程" TITLE="System.Threading.ThreadAbortException: 正在中止线程" /> LogError(ex.ToString, "~/ErrLog.txt")
http://www.web3.cn/Images/OutliningIndicators/InBlock.gif正在中止线程" TITLE="System.Threading.ThreadAbortException: 正在中止线程" /> ShowMessage(Me"该档案号已经在使用,或信息填写错误,无法保存!\n\n如果该档案号是录入错误而删除,请与管理员联系清空该档案号!")
http://www.web3.cn/Images/OutliningIndicators/InBlock.gif正在中止线程" TITLE="System.Threading.ThreadAbortException: 正在中止线程" /> End Try
http://www.web3.cn/Images/OutliningIndicators/InBlock.gif正在中止线程" TITLE="System.Threading.ThreadAbortException: 正在中止线程" /> 
http://www.web3.cn/Images/OutliningIndicators/ExpandedBlockEnd.gif正在中止线程" TITLE="System.Threading.ThreadAbortException: 正在中止线程" /> End Sub
 看看从网上找来的一些资料才明白是什么原因,按以下方法排除了此问题。
 

症状

如果使用 Response.EndResponse.Redirect 或 Server.Transfer 方法,将出现 ThreadAbortException 异常。您可以使用 try-catch 语句捕获此异常。
 

原因

Response.End 方法终止页的执行,并将此执行切换到应用程序的事件管线中的 Application_EndRequest 事件。不执行 Response.End 后面的代码行。

此问题出现在 Response.Redirect 和 Server.Transfer 方法中,因为这两种方法均在内部调用 Response.End
 

解决方案

要解决此问题,请使用下列方法之一:
对于 Response.End,调用 HttpContext.Current.ApplicationInstance.CompleteRequest 方法而不是 Response.End 以跳过 Application_EndRequest 事件的代码执行。
对于 Response.Redirect,请使用重载 Response.Redirect(String url, bool endResponse),该重载对 endResponse 参数传递 false 以取消对 Response.End 的内部调用。例如:

  Response.Redirect ("nextpage.aspx", false);            
如果使用此替代方法,将执行 Response.Redirect 后面的代码。
    对于 Server.Transfer,请改用 Server.Execute 方法。

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有