2

I have a process on a system that runs on IIS, it takes hours to finish so it runs on a thread.

The problem is that this thread is dropped after some time because the IIS process timeout (no activity). This thread can't stop in the middle.

How can I prevent this timeout if the thread is running?

H H
  • 263,252
  • 30
  • 330
  • 514
BrunoLM
  • 97,872
  • 84
  • 296
  • 452
  • 2
    Assuming that you can't configure the time-out in IIS? – Ewerton Sep 13 '11 at 18:56
  • 4
    Have you read the caveats of http://stackoverflow.com/questions/536681/can-i-use-threads-to-carry-out-long-running-jobs-on-iis ? – xanatos Sep 13 '11 at 18:56
  • 5
    Perhaps run it outside of IIS as a service? ("Hours" doesn't seem like an IIS task.) –  Sep 13 '11 at 18:57

1 Answers1

5

In the settings of the Application Pool in IIS you could configure it to not recycle the AppDomain after a certain period of inactivity. Notice however that using long running tasks in IIS is bad idea and this setting might not be 100% reliable. For example if your server starts running low on memory or high CPU usage IIS could still recycle it. IIRC this threshold could also be configured.

The best way would be to externalize those long running tasks as a separate Windows Service.

And if you cannot do any of those previous things and you are absolutely desperate the last thing you could try in your total despair is to auto-ping the web application from this background thread by sending HTTP requests at regular intervals to avoid it from dying. But once again that should really be the last thing you should attempt.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • Similar to: [How to keep ASP.NET assemblies in AppDomain alive](http://stackoverflow.com/questions/838318/how-to-keep-asp-net-assemblies-in-appdomain-alive#838348) – Randy Levy Sep 13 '11 at 19:11