Application lock state during Application start

  • Thread starter Thread starter APA
  • Start date Start date
A

APA

In the Application_Start event I load several static variables with data from the database that are critical to the execution of the application.
My question is that during app start if a second request comes in before app start is complete does it wait for app start to complete or does it go
straight to BeginRequest? It appears in some cases that begin request is being called before app start is finished. We know this because we test for
this static variable being null in BeginRequest. So, do I need to do Application.Lock() and Application.UnLock() in Application_OnStart to prevent
any requests from being processed until app start is complete? I would have thought that the default behavior would be to lock the application until
it is started.

Thx.
 
APA,
I doubt that employing the Application.Lock / Unlock methods would
accomplish your objective, as all they do is prevent modification of
Application objects by another thread until the Unlock method has completed.
Probably a safer and more reliable operation would be to figure out a way to
sleep a ver early Request until it can definitively gain access to non-null
static variables that you were setting in your Application_Start event.
I haven't got much background in this area and would defer to others who
have better ideas, but in the worst case scenario, you could abort a Request
that is not able to get access to the static variables by throwing an
appropriate exception, causing the user to have to try again.
Peter
 
Back
Top