您的位置:首页 > 其它

在try catch中使用Response.End()抛"线程被中止"异常

2009-05-12 22:00 573 查看
在try catch中使用Response.End()抛"线程被中止"异常,Response.Redirect()和Server.Transfer()也会出现这个问题.

如:(

Code

try

{

if (DoSomeThing())

{

Response.End();

//HttpContext.Current.ApplicationInstance.CompleteRequest();

}

//DoOtherThing不写在else里只是为了说明问题

DoOtherThing();

}

catch (System.Threading.ThreadAbortException ex)

{

WirteLog(ex);

}

catch (Exception ex)

{

WirteLog(ex);

}
)

如果不用catch (System.Threading.ThreadAbortException ex),就会抛"线程被中止"异常,

如果不用catch (System.Threading.ThreadAbortException ex),而用HttpContext.Current.ApplicationInstance.CompleteRequest 代替Response.End(),则后面的DoOtherThing()还是会继续执行.

要根据实际需要选择具体做法.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: