When Application_End isn't called in asp.net WebService
-
03-06-2021 - |
Frage
I know that in the following cases Apllication_end will be called:
- edit the config file for an application that's running.
- change a dll in the bin directory.
- stop (or restart) IIS.
- Process Recycling turned on either in IIS6 App Pools, or using the aspnet worker process.
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!
Lösung 2
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
Andere Tipps
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:
- an action caused IIS to restart the service process (changing a file would force this)
- the IIS service is shut down
- process recycling.
If the process is terminated abruptly (i.e killing the w3wp process), it won't get a chance to run.