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?
Process A runs managed code with one application domain while Process B runs managed code has three application domains. Note that Process C which runs unmanaged code has no application domain.
Application domains provide a unit of isolation for the common language runtime. They are created and run inside a process. Application domains are usually created by a runtime host, which is an application responsible for loading the runtime into a process and executing user code within an application domain.
An AppDomain provides a layer of isolation within a process. Everything you usually think of as "per program" (static variables etc) is actually per-AppDomain. This is useful for: plugins (you can unload an AppDomain , but not an assembly within an AppDomain )
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With