473,324 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Application_End is not fired when app unloaded. Why?

I am using Application_End to send out a notification about application being
unloaded. I found that those notifications are not being sent because the app
seems to get unloaded without Application_End ever being called. We started
logging Application_Start and Application_End events and found that the
number is not even: Application_Start happen more often than Application_End.
My question is: What are the sutuations in which we should expect
Application_End never being fired when application/process unloaded?
Nov 19 '05 #1
4 9119
1) are you sure the Application is ended?
2) what/how are you logging in the _end?
--
Curt Christianson
Site & Scripts: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Vlad Hrybok" <Vlad Hr****@discussions.microsoft.com> wrote in message
news:DD**********************************@microsof t.com...
I am using Application_End to send out a notification about application
being
unloaded. I found that those notifications are not being sent because the
app
seems to get unloaded without Application_End ever being called. We
started
logging Application_Start and Application_End events and found that the
number is not even: Application_Start happen more often than
Application_End.
My question is: What are the sutuations in which we should expect
Application_End never being fired when application/process unloaded?

Nov 19 '05 #2
1. Yes. The app has a thread that sends heartbeats to report it's alive. We
noticed that after heartbeats stop coming (application unloaded),
Application_End doesn't always come after that.

2. We log it to Event Viewer.

Thank you,
Vlad Hrybok.

"Curt_C [MVP]" wrote:
1) are you sure the Application is ended?
2) what/how are you logging in the _end?
--
Curt Christianson
Site & Scripts: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Vlad Hrybok" <Vlad Hr****@discussions.microsoft.com> wrote in message
news:DD**********************************@microsof t.com...
I am using Application_End to send out a notification about application
being
unloaded. I found that those notifications are not being sent because the
app
seems to get unloaded without Application_End ever being called. We
started
logging Application_Start and Application_End events and found that the
number is not even: Application_Start happen more often than
Application_End.
My question is: What are the sutuations in which we should expect
Application_End never being fired when application/process unloaded?


Nov 19 '05 #3
Hi, Vlad.

Are you running on IIS5 or IIS6 ?

If you're running on IIS 5.x, the ASP.NET service runs
under the ASPNET account, and that account has to be
granted privileges in order to write to the Event log.

If you're running on IIS 6, the ASP.NET service runs
under the NETWORK SERVICE account, and that
account has to be granted privileges in order to write
to the Event log.

Does your logging work OK when the Application_End
event does occur ? Or does the logging never happen ?

I did a little test, running on IIS 6, to check out if
Application_OnEnd firs when the Application is
forced to end ( and restart ).

Here's something I wrote which works every time
Application_OnEnd fires ( note: *not* Application_End):

First, grant the appropiate account
(ASPNET or NETWORK SERVICE) write permission
on any directory you'd like a text file to be written to,
depending on whether you're running IIS5.x or IIS 6.

Then, test this global.asax, which only has a WriteFile
function in the Application_OnEnd event :

global.asax:
------------
<%@ Application Language="C#"%>
<script runat="server">

protected void Application_OnEnd(Object sender, EventArgs e)
{
WriteFile("Application Ended ");
}
void WriteFile(string strText)
{
System.IO.StreamWriter writer = new System.IO.StreamWriter(@"c:\test.txt",true);
string str;
str = strText + " " + DateTime.Now.ToString( );
writer.WriteLine(str);
writer.Close( );
}
</script>
---------------

Now, open any *.aspx file in the Application, and then open the
global.asax file in notepad and hit enter to move the text in it
one line down and again back up one line, and save the file.

Editing global.asax will force Application_OnEnd to fire.

You should wind up with a text file in whatever directory
you designated in global.asax, with text similar to this :

------------------------------------------------------------
Application Ended 1/11/2005 2:23:51 AM
------------------------------------------------------------

It should work the same for your Event Logging.

If it doesn't, since this does, you could setup a
FileSystemWatcher Console app to do the logging
for you when changes are made to the text file.

See
http://msdn.microsoft.com/library/de...ClassTopic.asp
for sample code to do that.

Just substitute your logging code for this line:
Console::WriteLine(S"File: {0} {1}", e->FullPath, __box(e->ChangeType));

Try it out, and let us know how you do.


Juan T. Llibre
ASP.NET MVP
===========
"Vlad Hrybok" <Vlad Hr****@discussions.microsoft.com> wrote in message
news:73**********************************@microsof t.com...
1. Yes. The app has a thread that sends heartbeats to report it's alive.
We
noticed that after heartbeats stop coming (application unloaded),
Application_End doesn't always come after that.

2. We log it to Event Viewer.

Thank you,
Vlad Hrybok.


Nov 19 '05 #4
Juan,
It's IIS 6 on Windows 2003 Server, but logging to the event log is not an
issue - we log just fine. (BTW, to write to the event log you don't have to
grant NETWORK SERVICE any privileges - as long as event source alredy exists
you can write into it from under NETWORK SERVICE just fine, and we create the
event source during the app installation. But it's besides the point.) The
problem is that Application_End doesn't seem to be called sometimes. I need
to determine when it's not being called. When I'm debugging the app and do
standard things that restart the app, like touching web.config or recycling
the app pool - I see application_end called fine. But there is a scenario
where you can see Start events logged and End not. It happens only when
debugging, but I wonder if something like this can happen during normal app
lifecycle?
To reproduce:
1. Build an app that logs Application_Start and Application_End events.
2. Run it by selecting Debug | Start from the menu so that browser opens up.
Observe Application_Start event logged.
3. Close the browser so that debug session ends.
4. Do Build | Rebuild from the menu.
5. Run the app again by selecting Debug | Start from the menu. Observe
Application_Start being logged w/o Application_End being logged.

Note: If you run the same scenarion one more time with one change: run the
app without the debugger, you will see Application_End being logged. The
purpose of the demo was to show that there can be situations when
Application_End not being called. Our problem in production is most likely
something else. Any idea what it could be?

Regards,
Vlad.

Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Alistair Saldanha | last post by:
I'm looking for the event that is fired by Internet Explorer to an "alert": <SCRIPT> Alert("You already have a session open") </SCRIPT> The event would be webBrowser.Document.???? Much...
4
by: Matt Sawyer | last post by:
I am attempting to use an API (CxApiOem.dll) that has a large number of defines and complicated structs. It's just too much hassle to attempt to use DLLImport to make the desired API calls. ...
2
by: Craig | last post by:
Hi, I'm having difficulty understanding how the Application_End event in the Global.asax file gets called. I thought that it's called when the specific web site is stopped via the IIS management...
3
by: Jim Owen | last post by:
My .Net book states that the Application_End event handler in Global.asax gets called typically about 20 minutes after the last HTTP request. My question is: what is the best way to debug my...
4
by: Halcyon Woodward | last post by:
I have an odd problem... We have a small development team (three coders) working on the same project (a C# web application). Each coder has a unique 'sandbox' site on a shared Windows 2003...
4
by: J-T | last post by:
I have my applciation installed in an appplication pool (a worker process) -IIS 6.0-which is defined to be shut down after 20 minutes of being idle.If I put a breakpoint in Application_End method...
1
by: an | last post by:
I've implemented a call-back function to repopulate the stored Cache objects when they expires or are removed it works great but in one situation only it doesen't work (that is the callback...
4
by: =?Utf-8?B?c2Vhbl9tY2Fk?= | last post by:
I have now confirmed that my application level objects are being killed during worker process “recycle”. I was going to write some code to re-create these objects at the Application_Start event...
5
by: Tenacious | last post by:
I am trying to shutdown a database server in the Application_End event handler on the Global.asax page. So far I am trying this only on the development server that comes with Visual Studio 2005....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shllpp 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.