How to start code when IIS starts - Any expert?

  • Thread starter Thread starter AW
  • Start date Start date
A

AW

Hello,

I have a method to initialize my application, which reads configuration
settings, establishes connections, and loads a bunch of data. It lasts for
several seconds.

This method is called in the Application_Start event, but this means that
the first person requesting for a page will undergo a severe wait.

Can someone recommend a way to do so that I can call this method BEFORE any
page is called? Do I have to plug into IIS and know when the server is
started?

Thanks,
AW
 
Your best bet is to do it the way you are doing it. The application will
only start when someone hits the page. It will also unload 20 minutes after
the last session is killed. This is an excellent way to do it in order to
get the memory management features and ensure application stability and
performance. Your best bet instead may be to have a windows task sitting
somewhere that just hits a particular page every 19 minutes. That way
ensuring that there's always a session in the application domain so it won't
unload and if a user hasn't hit the site yet the app will be forced to load.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - Frontpage
 
Thanks Mark for your answer.

I understand that it would be best to theoretically wait for the first user
to start the application, but practically this can't be tolerated because of
the several seconds needed for initialization.

The workaround that you mention seems like a good idea, but isn't it
possible to do something that's more tightly tied with IIS? I mean, instead
of making an HTTP request, can't I call directly an IIS API or, better an
ASP.Net API?

Thanks for your help.
 
AW,

Here are some suggestions that may help your situation:

1.) Compile your .dll with the method you call in application_onstart into a
native image using ngen.

2.) Cache the data you retrieve and use either timespan or file dependencies
to refresh the cache appropriately.

That should give you some of the performance boost you're seeking.

Regards,

Bryce Budd
 
Thanks Bryce.

These are good ways to speed up the initialization part, but still a good
part of the work can't be optimized (database connections establishment, for
instance). So I really need a way to do this part of the work *before*
anybody uses the application, instead of just speeding it up.
 
Back
Top