I know that in the following cases Apllication_end will be called:
but my question is what are the cases when it's won't be called?
I know it won't be called if you manually End w3wp process or if the server will brutally shut down.
Is there any other scenarios?
Thanks!
The answer to your question is basically in your question already. Application_End is called anytime the process hosting your web service shuts down gracefully.
The only time this would happen is:
If the process is terminated abruptly (i.e killing the w3wp process), it won't get a chance to run.
It seems that the brutal shut down can be caused by OutOfMemoryException that caused failure in creating AppDomain that are needed for executing requests. In this scenario Application_end won't be called.
Event Type: Error
Event Source: ASP.NET 2.0.50727.0
Event Category: None
Event ID: 1334
Date: 4/22/2012
Time: 11:23:13 AM
User: N/A
Computer: CCBSHAIS02
Description:
Failed to initialize the AppDomain:/LM/W3SVC/1/Root/AgentWSException: System.SystemException
Message: Failed to create AppDomain.
StackTrace: at System.Web.Hosting.ApplicationManager.CreateAppDomainWithHostingEnvironment(String appId, IApplicationHost appHost, HostingEnvironmentParameters hostingParameters) at System.Web.Hosting.ApplicationManager.CreateAppDomainWithHostingEnvironmentAndReportErrors(String appId, IApplicationHost appHost, HostingEnvironmentParameters hostingParameters)
InnerException: System.OutOfMemoryException
Message: Exception of type 'System.OutOfMemoryException' was thrown.
StackTrace: at System.AppDomain.nCreateDomain(String friendlyName, AppDomainSetup setup, Evidence providedSecurityInfo, Evidence creatorsSecurityInfo, IntPtr parentSecurityDescriptor) at System.AppDomain.CreateDomain(String friendlyName, Evidence securityInfo, AppDomainSetup info) at System.Web.Hosting.ApplicationManager.CreateAppDomainWithHostingEnvironment(String appId, IApplicationHost appHost, HostingEnvironmentParameters hostingParameters)
for further reading on IIS and AppDomains look at: http://weblogs.asp.net/owscott/archive/2007/09/02/application-vs-appdomain.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With