ASP.NET AppDomain - User code at Initialization

  • Thread starter Thread starter csprakash
  • Start date Start date
C

csprakash

Hi All,
I want to run some user when an Application is started, or when a
worker process is started. Application_Start, 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
"AppDomainInitializer", is this of any use? Can it be configured in
IIS to invoke user code?

Any inputs/pointers will be very helpful.

Thanks,
Ashton
 
Hello (e-mail address removed),

What exactly behavior u need and why Application_Start is inappropriate?

Im not quite understand how u gonna hook the AppDomain when asp.net starts
to add AppDomainInitializer 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
 
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_Start. The initialization takes around 3 minutes.
-------------
Application_Start(..)
{
......
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 (HttpApplication),
------------
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.Administration ServerManager, Site,
ApplicationPool, ApplicationDomain classes. Can anyof them be used to
start HttpApplication even before an external http request comes?

Regards
 
Back
Top