ASP.NET AppDomain - User code at Initialization

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • csprakash@yahoo.com

    ASP.NET AppDomain - User code at Initialization

    Hi All,
    I want to run some user when an Application is started, or when a
    worker process is started. Application_Sta rt, Init methods of
    HttpApplication in Global.asax.cs are of not use, as they are called
    only on the first call to an aspx page in the application. They are
    not called during the initialization of the worker process (or)
    Application Domain.

    Is this possible at all? I came accross a delegate
    "AppDomainIniti alizer", is this of any use? Can it be configured in
    IIS to invoke user code?

    Any inputs/pointers will be very helpful.

    Thanks,
    Ashton
  • Michael Nemtsev [MVP]

    #2
    Re: ASP.NET AppDomain - User code at Initialization

    Hello csprakash@yahoo .com,

    What exactly behavior u need and why Application_Sta rt is inappropriate?

    Im not quite understand how u gonna hook the AppDomain when asp.net starts
    to add AppDomainInitia lizer event

    ---
    WBR,
    Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour

    "The greatest danger for most of us is not that our aim is too high and we
    miss it, but that it is too low and we reach it" (c) Michelangelo

    Hi All,
    I want to run some user when an Application is started, or when a
    worker process is started. Application_Sta rt, Init methods of
    HttpApplication in Global.asax.cs are of not use, as they are called
    only on the first call to an aspx page in the application. They are
    not called during the initialization of the worker process (or)
    Application Domain.
    >
    Is this possible at all? I came accross a delegate
    "AppDomainIniti alizer", is this of any use? Can it be configured in
    IIS to invoke user code?
    >
    Any inputs/pointers will be very helpful.
    >
    Thanks,
    Ashton

    Comment

    • Ashton

      #3
      Re: ASP.NET AppDomain - User code at Initialization

      My requirement is - I have a time consuming Initialization that needs
      to be done before any page is accessed on the site. At present I am
      using Application_Sta rt. The initialization takes around 3 minutes.
      -------------
      Application_Sta rt(..)
      {
      ......
      myObj = new MyClass(); // takes 3 minutes, performs singleton type of
      initialization internally
      }
      -------------

      So, when I first access the site, the browser looks frozen. I dont
      want the initialization to wait till a request comes, if it can start
      as soon as the IIS ApplicationPool is started or recycled, that will
      be ideal.

      I had few alternatives, but none of them are elegant:

      1)
      On a machine restart, after IIS service comes up, I can have a bat
      script which tries to access the site, which performs the
      intialization.
      This works fine, but the worker processes need to be recycled
      every hour or so for some data requirement. Whenever the worker
      process is recycled, it waits till it receives the first request for
      the Application. On the first request, the users feel the site is
      frozen.

      2) tried various other methods in Global.asax.cs (HttpApplicatio n),
      ------------
      init()
      {
      ......
      myObj = new MyClass(); // takes 3 minutes, performs singleton type of
      initialization internally
      }
      ---------
      static global()
      {
      ......
      myObj = new MyClass(); // takes 3 minutes, performs singleton type of
      initialization internally
      }

      but both of them are invoked on the first http request to the
      Application.

      3) I came across Microsoft.Web.A dministration ServerManager, Site,
      ApplicationPool , ApplicationDoma in classes. Can anyof them be used to
      start HttpApplication even before an external http request comes?

      Regards

      Comment

      Working...