Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Thread was being aborted

I am using Server.Transfer. Everything works fine, but exception log shows following exception.

System.Threading.ThreadAbortException: Thread was being aborted.    at System.Threading.Thread.AbortInternal()    at System.Threading.Thread.Abort(Object stateInfo)    at System.Web.HttpResponse.End()    at System.Web.HttpServerUtility.Transfer(String path, Boolean preserveForm)    at System.Web.HttpServerUtility.Transfer(String path) 

Any idea to avoid above exception.

like image 308
Syed Tayyab Ali Avatar asked Sep 16 '09 14:09

Syed Tayyab Ali


People also ask

What causes a thread Abort?

When a call is made to the Abort method to destroy a thread, the common language runtime throws a ThreadAbortException . ThreadAbortException is a special exception that can be caught, but it will automatically be raised again at the end of the catch block.

What is thread Abort?

Abort(Object) Obsolete. Raises a ThreadAbortException in the thread on which it is invoked, to begin the process of terminating the thread while also providing exception information about the thread termination. Calling this method usually terminates the thread.


2 Answers

This exception is throw by the call to Server.Transfer in order to halt the execution of the current method - exactly the same thing gets thrown if you do Response.Redirect.

The two choices you have are:

  • Catch and rethrow the ThreadAbortException / reperform the Server.Transfer
  • Make sure that you only do Server.Transfer in places where it wont be caught (recommended)

EDIT: Scratch that, http://support.microsoft.com/kb/312629 has a couple of other suggestions to try, but I still recommend #2 above.

like image 55
Justin Avatar answered Oct 15 '22 21:10

Justin


Another way to solve this, is to catch the generated error and to not rethrow it:

        catch (ThreadAbortException)         {          } 
like image 37
Chris Ghysbrecht Avatar answered Oct 15 '22 21:10

Chris Ghysbrecht