Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Determine ASP.NET Application Domain Lifetime

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?

like image 834
Bleser Avatar asked Sep 22 '10 19:09

Bleser


People also ask

How many application domain can be used in single process?

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.

What is application domain in asp net?

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.

What is the app 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 )


2 Answers

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.

like image 55
Conrad Frix Avatar answered Sep 19 '22 22:09

Conrad Frix


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.

like image 20
Bleser Avatar answered Sep 18 '22 22:09

Bleser