Applicaation_Start doesn't always fire ?

P

Patrice

Hi all,

Got a strange problem.

In Application_Start, I just store the current date/time in an application
variable to keep track of the last time the application started.

To my surprise, I noticed in my error reporting log (that dumps various
things including this application variable) that sometimes this application
variable is not set.

I then added in beginrequest some code to fill the same application variable
all along with the event that set it (if not already set).

For now it looks like :
- if I update the web application (dll, web.config etc...) the global
variable shows the correct date/time set in application_start
- then the next day, the application variable generally shows today's date
and was set from beginrequest earlier in the day.

It occurs even when pages were accessed less than 20 minutes earlier the
alleged restart.

For now it would seem to me that when the application pool is
stopped/restarted by IIS or something similar, the application looses its
application variables. The variable is then set in the begin_request event.

It doesn't cause any problem as I have nothing special in this event but I
really like to undestansd what is happening...
Thanks in advance.
 
T

Thomas Hansen

Hi all,

Got a strange problem.

It isn't very strange, in fact Application_Start only fires _when the
application starts_
Normally after an Application_End... ;)

This doesn't nessecary happen every "n'th hour" or when you press F5 in
de debugger etc...
Under perfect circumstances the Application_Start will be called ONCE
and then NEVER again until END OF TIME...!!
:)

..t
 
P

Patrice

Yes, but it looks like at some point I loose the application variable that
is defined in Application_Start. Then as, it doesn't exist any more it is
set in BeginRequest.

I assumed this was because the application stopped (loosing application
variables) and was restarted without application_start being fired (which
would have populate again the variable). As the application variable is not
populated yet then beginrequest populate it... This is the behavior I see.

That said you made me think that it could be something else. The application
perhaps doesn't restart at all but for some reason, I loose the application
variable. I'll try to see if something could cause this...
 
P

Patrice

I saw in a past error report that I have a session start (I also track this
one) that is earlier than the time at which the application variable has
been populated again.

So it definitely looks like the problem is not that the application restarts
but that it looses this application variable for some other reason. I'll try
to see if I have some code that could cause this...

Back on a new track... Thanks.


Patrice said:
Yes, but it looks like at some point I loose the application variable that
is defined in Application_Start. Then as, it doesn't exist any more it is
set in BeginRequest.

I assumed this was because the application stopped (loosing application
variables) and was restarted without application_start being fired (which
would have populate again the variable). As the application variable is
not populated yet then beginrequest populate it... This is the behavior I
see.

That said you made me think that it could be something else. The
application perhaps doesn't restart at all but for some reason, I loose
the application variable. I'll try to see if something could cause this...
 
J

Juan T. Llibre

re;
I saw in a past error report that I have a session start (I also track this one) that is earlier
than the time at which the application variable has been populated again.

That's impossible.

Application_Start fires earlier that Session_Start.
It's the first event for all ASP.NET Applications and must fire before any other events fire.

See:
http://msdn2.microsoft.com/en-us/library/ms178473.aspx

re:
So it definitely looks like the problem is not that the application restarts but that it loses
this application variable for some other reason.

That is highly unlikely.

Are you using Application.Lock when you set the application variable ?
 
M

Mark Rae

I saw in a past error report that I have a session start (I also track this
one) that is earlier than the time at which the application variable has
been populated again.

That simply can't happen...
 
A

Arundhati Anavekar

try to track the sequecne of enevts by injecting Print-to-file
statements in global.asax it should return:

Application_Start
Application_BeginRequest
Application_AuthenticateRequest
Session_Start
Application_EndRequest
Application_BeginRequest
Application_AuthenticateRequest
Application_EndRequest
Application_BeginRequest
Application_AuthenticateRequest
Application_EndRequest
Session_End
Application_End

but you will notice that even after to close the application, the file
is not created immediately but after sometime, this is because IIS does
not immediately release the application space thus Application_End is
not instantly called. your guess that "application pool is
stopped/restarted by IIS or something similar," or some reason the
variable value is getting lost and gained without a proper path. I
understand my writing may not make much help but tracking the flow
could help reach a solution.
 
P

Patrice

I was thinking more to something like having Application.Clear somewhere.
That would clear the application variable but would left session variables
unchanged.

Let's rephrase the problem wihtout any assumption from my part.

The Application_Start event stores a " _Start" applciation variable that has
the current date/time of the event (not using lock).

The only usage of this application variable is to be dumped in error
reports. It is only read, never written once stored...

I see this variable in some other reports but starting at some point, this
variable is no more available in error reports...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,149
Latest member
Vinay Kumar Nevatia0
Top