Does anyone know of a way to replace httpResponse.End()
with something that does not throw a ThreadAbortException
causing issues with performance? Someone suggested doing a 'HttpContext.Current.ApplicationInstance.CompleteRequest()', but this doesn't do everything httpResponse.End()
does, like sending buffered data to the client which is a problem for me.

- 3,992
- 10
- 49
- 81
-
Do you have any indication that the exception is *really* causing an issue with performance? How many times is it being thrown every second, and how CPU-bound is your server? – Jon Skeet Jan 24 '13 at 20:27
-
I am not sure, but the QA team at my company seems to believe so. – Art F Jan 24 '13 at 20:55
-
Your QA team should provide *evidence* of this then. (Exceptions aren't hugely cheap, but equally unless you're processing tens of thousands of requests per second on a single machine, I'd expect them to get lost in the noise.) – Jon Skeet Jan 24 '13 at 21:01
2 Answers
Firstly, I doubt that this is really causing significant problems. However, it's not generally a great idea anyway... it's an abuse of exceptions, really. (IMO, anyway.)
From the documentation:
This method is provided only for compatibility with ASP—that is, for compatibility with COM-based Web-programming technology that preceded ASP.NET. If you want to jump ahead to the EndRequest event and send a response to the client, call
CompleteRequest
instead.
Obviously the current method will still continue after you call CompleteRequest
, so you'll need to make sure you complete the handling of the current event cleanly.

- 1,421,763
- 867
- 9,128
- 9,194
Ok, I was able to find the answer here. If you scroll down to the answer by 'Jay Zalos'. I replaced httpResponse.End()
with the following 3 lines:
Response.Flush()
Response.SuppressContent = True
HttpContext.Current.ApplicationInstance.CompleteRequest()
-
I don't think this is a good solution. The fact that you need SuppressContent indicates that some strange things are happening (generating content that is never sent...). Also Flush is a perf problem (even if executed only once per request). Please do not mark this as the answer. It will mislead future visitors to think this is best practice. – usr Jan 24 '13 at 21:29