Unexpected ThreadAbortException in a function

90 Views Asked by At

We have an application that calls a function after interval of 5 minutes(using timer) from Glabal.asax

The function communicates with third parties, gets data and sends it to another application that updates the database.

After 4th or 5th time the function is called, a ThreadAbortException is called while receiving data from 3rd party application. This stops the entire application.

We don't use Response.End, Response.Redirect or Server.Transfer which are the functions that cause ThreadAbortException.

Application pool might get restarted/recycled. But what can be cause of this? I changed the timeout to 0 which means it will never timeout. But I am still getting the exception.

Can anyone suggest anything?

Thanks.

1

There are 1 best solutions below

0
Dhanashree On BEST ANSWER

I was using a WebRequest object to make request to the third party. The solution to the problem is to change the timeout of the request. I changed it to infinite.

WebRequest request = WebRequest.Create(serviceUrl);
request.Method = "POST";
request.Timeout = System.Threading.Timeout.Infinite;

I hope this helps someone who encounters similar situation. I was helped by my colleague though.

Edit - I also found an interesting article on MSDN - Understanding WebRequest Problems and Exceptions