This KB Article says that ASP.NET\'s Response.End()
aborts a thread.
Reflector shows that it looks like this:
public void End()
{
I disagree with the statement "Response.End is harmful". It's definitely not harmful. Response.End does what it says; it ends execution of the page. Using reflector to see how it was implemented should only be viewed as instructive.
My 2cent Recommendation
AVOID using Response.End()
as control flow.
DO use Response.End()
if you need to stop request execution and be aware that (typically)* no code will execute past that point.
* Response.End()
and ThreadAbortExceptions.
Response.End()
throws a ThreadAbortException as part of it's current implementation (as noted by OP).
ThreadAbortException is a special exception that can be caught, but it will automatically be raised again at the end of the catch block.
To see how to write code that must deal with ThreadAbortExceptions, see @Mehrdad's reply to SO How can I detect a threadabortexception in a finally block where he references RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup Method and Constrained Execution Regions
The Rick Strahl article mentioned is instructive, and make sure to read the comments as well. Note that Strahl's issue was specific. He wanted to get the data to the client (an image) and then process hit-tracking database update that didn't slow down the serving of the image, which made his the problem of doing something after Response.End had been called.