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

如:(


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

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

相关文章:

  • 2022-12-23
  • 2022-01-06
  • 2021-05-22
  • 2022-12-23
  • 2022-12-23
  • 2021-07-30
  • 2021-09-24
  • 2021-07-16
猜你喜欢
  • 2021-05-28
  • 2021-06-08
  • 2022-01-19
  • 2022-12-23
相关资源
相似解决方案