views:

42

answers:

2

We have an application gathering counter statistics and we would like the values to reset after executing the iisreset command and that's all.

Microsoft says Application_Start is:

Called when the first resource (such as a page) in an ASP.NET application is requested. The Application_Start method is called only one time during the life cycle of an application. You can use this method to perform startup tasks such as loading data into the cache and initializing static values.

This is how we're currently doing it:

protected void Application_Start(object sender, EventArgs e)
{
    _counters.Get<AutoCounter>("TAS:RequestCount").Reset();
    _counters.Get<AutoCounter>("TAS:RequestTime").Reset();
    _counters.Get<AutoCounter>("TAS:TimeBetweenErrors").Reset();
    _counters.Get<AutoCounter>("TAS:ErrorCount").Reset();
}

However, these are resetting at unexpected intervals. What determines when the application domain's life-cycle ends and this method is called on the next request?

+1  A: 

There are a lot of reasons why a Web app gets restarted. This article includes the following partial list.

  • the web.config is edited

  • the machine.config is edited

  • the global.asax is edited

  • files are changed in the bin
    directory of the web app, or one of
    the bin's subdirectories

  • a directory is created, renamed, or
    deleted within a web app directory

  • an ASP.NET file (aspx, asmx, etc.) is edited (and therefore recompiled)
    more than 20 times, a default set in the machine config as an element
    named numRecompilesBeforeApprestart

  • by way of settings of various
    attributes in the
    element in the machine.config, which affect the restart/shutdown of the
    worker process itself. On Windows
    2003, when not using IIS5 isolation
    mode (which is not used by default), these elements are
    ignored and instead the settings in
    Application Pools in IIS manager are used

My guess is that your approach is good but now what you really want to know is what's causing the restart and if you should be alarmed.

Conrad Frix
@Conrad, thank you for the suggestions. I can assure that none of the configuration files are being edited, so it is most likely IIS settings causing the unexpected restarts.
Bleser
A: 

In IIS 6.0, the application pool performance tab allows you to shutdown the IIS worker process after a specified idle time. This is enabled by default and is set to twenty minutes.

This could be the cause of unexpected application_start events being triggered.

Bleser