I came across an SO question that discussed the use of ApplicationInstance.CompleteRequest()
to avoid a ThreadAbortException
being thrown when Response.End()
is called.
In the past, to avoid the exception error I mentioned above, I have used this overload: Response.End(false)
.
I am trying to understand what are the differences between the two methods. Why would I choose to use ApplicationInstance.CompleteRequest()
in place of Response.End(false)
?
EDIT:
I understand that ApplicationInstance.CompleteRequest()
is the more correct way of doing things, but the one feature that calling Response.End(true)
that is missing is not processing the rest of the code that follows. Sometimes, we do not want to continue with the processing, but want to end the execution right there and then.
Maybe answering my own question here, but maybe the correct way of doing things is to write the code so that when ending the response (and not aborting the thread), there are no more lines of code to process.
An example:
[DO SOME WORK]
if ([SOME CONDITION])
{
ApplicationInstance.CompleteRequest();
}
else
{
//continue processing request
}
This may work, but it seems like we are coding here to deal the limitations of the method. And can lead to some messy code.
Am I missing something here?