Creating Understanding and Educating Programmers, Developers and Technical Communities, one post at a time.

Wednesday, October 7, 2009

Thread was being aborted

I was working on project. Everything was fine but exception log showed "Thread was being aborted". I further looked into and found out System.Threading.ThreadAbortException:

It is because Response.Redirect and Server.Transfer methods take me to another page and call Response.End internally. Response.End immediately ends the page execution and shifts the execution to the Application_EndRequest event in the application's event pipeline. This make impossible to execute current page code.

You can avoid such exception by using overload method of Response.Redirect(string url, bool endResponse), and pass false value for second argument. It will suppress the interal call to Response.End.

You can use Server.Execute instead of Server.Transfer.

4 comments:

  1. In my case, it's not working

    ReplyDelete
  2. In my case also, it's not working

    ReplyDelete
  3. server.execute is displaying the previous page also

    ReplyDelete
  4. ya response.redirect(url,bool value ) is working fine

    ReplyDelete