9

How do I prevent an ASP.Net site from being unloaded by IIS?

I have what may be the dumbest website in the world - once per hour it wakes up and writes a timestamp to a log file. When the app starts, it says so with a timestamp in the log, and when it dies, same thing.

In IIS I went into its Application Pool and set the Idle Timeout to 0 and set Generate Recycle Event Log Entry > Regular Time Interval to False.

Yet the site still unloads itself about once per day - I get the App Unloading... entry in the log and it sits dead until I next visit it.

How do I prevent it from unloading?

(Obviously this site will do more once I get this resolved - for now it's as simple as possible to isolate the problem.)

Chris Moschini
  • 36,764
  • 19
  • 160
  • 190
  • 3
    Perhaps you should be using a windows service, or a scheduled task for this, instead of a website. – Oded May 04 '11 at 20:16
  • Yeah this is a regularly running task that's part of a much larger website (once this is resolved). Breaking it into a windows service involves a lot of install nonsense I don't want to deal with for scaling, and there's a lot more to deal with around sharing memory. I just want a site that doesn't get unloaded over and over. – Chris Moschini May 04 '11 at 20:50

2 Answers2

18

The application pool has another property that causes it to be automatically recycled every N minutes (defaults to 1740, or every 29 hours.) Make this zero to disable recycling. The property is (on IIS7) under the "Recycling" heading and is called "Regular Time Interval (minutes)"

jlew
  • 10,491
  • 1
  • 35
  • 58
1

In addition to @jlew's recommendation, the guidance in this article is important if you're running a background task/timer continuously/periodically in ASP.Net without the install/configuration/maintenance burden of Windows Services and Scheduled Tasks:

http://haacked.com/archive/2011/10/16/the-dangers-of-implementing-recurring-background-tasks-in-asp-net.aspx

It includes a useful helper library, WebBackgrounder, which abstracts the advice in the article to handle graceful shutdown and some of the typical wants/needs of a background task.

It does not configure IIS for you - you'll need to modify the recycling settings yourself.

Chris Moschini
  • 36,764
  • 19
  • 160
  • 190