我是靠谱客的博主 积极楼房,这篇文章主要介绍在try catch中使用Response.End()抛"线程被中止"异常,现在分享给大家,希望可以做个参考。

在try catch中使用Response.End()抛"线程被中止"异常,Response.Redirect()和Server.Transfer()也会出现这个问题.

如:(

contractedblock.gif expandedblockstart.gif 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()还是会继续执行.

要根据实际需要选择具体做法.

转载于:https://www.cnblogs.com/gergulo/archive/2009/05/12/1455241.html

最后

以上就是积极楼房最近收集整理的关于在try catch中使用Response.End()抛"线程被中止"异常的全部内容,更多相关在try内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(87)

评论列表共有 0 条评论

立即
投稿
返回
顶部