2

Background

I have a batch processing system that needs to send out messages (via SMS/Email) to groups of people.

As our message publihsing system is fairly slow, when the user hits the "send" button, the system posts all the message informtion into a database with a "batch ID" and then does an Asynchronise call (WebRequest.BeginGetRequest) to a "ProcesBatch" ASHX handler request, with the batch ID as a URL request parameter.

This releases the front end page back to the user to do the next batch of messages as the users dont actually need any feedback, however, the recording in the database is subsequently used in a reporting module.

In the mean time, the batch process handler simply cycles around the records from the database for the given batch ID and then posts the messages to our (slow) message publisher sequentially.

The Problem

The problem is that during the batch processing, asp.net is throwing a

System.Threading.ThreadAbortException: Thread was being aborted.

half way through and the remaining messages are not sent.

I have checked IIS and the recycle mins is set at the default 1740 so is there anything else that would cause this?

Or is there a more appropriate way to approach this.

Chris Hammond
  • 2,064
  • 5
  • 27
  • 53
  • 1
    You could use a windows service instead of an async function that runs on your webserver – RononDex Dec 18 '13 at 12:53
  • That is something that I have thought about and is my "back-stop" option if its just one of those uncontrollable IIS/ASP.Net things. – Chris Hammond Dec 18 '13 at 12:55
  • 1
    `Response.Redirect` will throw a ThreadAbortException, as I mention [in this SO answer](http://stackoverflow.com/questions/13727422/can-endresponse-increase-performance-of-asp-net-page/13727769#13727769), depending on how you use it. Maybe see if doing `Response.Redirect(url, false);` helps. But like @RononDex said, windows service would be more fitting for this. – MikeSmithDev Dec 18 '13 at 13:59
  • @MikeSmithDev - I'm not actually doing any redirects. The main user page executes an async "WebRequest.BeginGetResponse" to the ASHX handler. And the ASHX handler is then (occassionally) getting the thread abort. – Chris Hammond Dec 18 '13 at 14:10

1 Answers1

2

Have you tried to increase executionTimeout under httpRuntime in web.config?
The default value is 90 or 110 seconds (depending .net version).
Perhaps your ashx requires more time to end its job
http://msdn.microsoft.com/en-us/library/vstudio/e1f13641(v=vs.100).aspx

Edit: in general it's not a good idea to set a very long executionTimeout. As other users suggested, consider to develop a Windows Service to do the long jobs.

Fabrizio Accatino
  • 2,284
  • 20
  • 24
  • Thanks Fabrizio, looking at the link certainly has thrown light on why I don't have issue when running in debug mode in Visual Studio as the exectionTimeout setting only comes into effect release mode and its on my ACC server that I get issues. – Chris Hammond Dec 19 '13 at 08:24
  • 1
    Chris, afaik executionTimeout is skipped if you set – Fabrizio Accatino Dec 19 '13 at 08:28
  • If you can, please, share source code and the full exception (and inner exceptions). – Fabrizio Accatino Dec 19 '13 at 08:54
  • 1
    Fabrizio... I've run a few tests and it is, indeed, the `exectionTimeout` value. Short of setting this to an unfeasibly large number, I think the "service" route will have be the way forward. – Chris Hammond Dec 19 '13 at 09:44