protected void Application_End(object sender, EventArgs e) { var runtime = (HttpRuntime)typeof(HttpRuntime).InvokeMember("_theRuntime", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.GetField, null, null, null); if (runtime != null) { string shutDownMessage = (string)runtime.GetType().InvokeMember("_shutDownMessage", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField, null, runtime, null); string shutDownStack = (string)runtime.GetType().InvokeMember("_shutDownStack", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField, null, runtime, null); ApplicationShutdownReason shutDownReason = (ApplicationShutdownReason)runtime.GetType().InvokeMember("_shutdownReason", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField, null, runtime, null); LogHelper.WriteCustom(string.Format("Application_End:shutDownMessage:\r\n{0}\r\nshutDownStack:\r\n{1}\r\nshutDownReason:\r\n{2}\r\n", shutDownMessage, shutDownStack, shutDownReason.ToString()), @"Application\", false); } }
/// <summary> /// Stops this instance. /// </summary> public static void Shutdown(ApplicationShutdownReason shutdownReason) { var shutdownReasonText = shutdownReason.ConvertToString(); if (!_isWebFarmEnabledAndUnlocked) { return; } if (_startStage != 2) { LogException($"Web Farm cannot shutdown properly when at stage {_startStage}"); return; } Debug($"Shutdown ({shutdownReasonText})"); // Stop the polling interval _pollingInterval.Stop(); // Announce to other nodes, unless I am being overlapped recycled. // If I am being overlapped recycled, then my twin is taking over // and I am not really shutting down. var isOverlappedRecycling = IsOverlappedRecycling(); if (!isOverlappedRecycling) { PublishEvent(EventType.Shutdown, payload: shutdownReasonText); } using (var rockContext = new RockContext()) { if (!isOverlappedRecycling) { // Update IsActive = false, StoppedDateTime = now // If IsCurrentJobRunning = true set this to false var webFarmNode = GetNode(rockContext, NodeName); webFarmNode.IsActive = false; webFarmNode.StoppedDateTime = RockDateTime.Now; webFarmNode.IsCurrentJobRunner = false; } // Add a note if recycling var recyclingText = isOverlappedRecycling ? "Recycling - " : string.Empty; // Write to ClusterNodeLog shutdown message AddLog(rockContext, WebFarmNodeLog.SeverityLevel.Info, _nodeId, EventType.Shutdown, $"{recyclingText}{shutdownReasonText}"); rockContext.SaveChanges(); } _startStage = 0; }
internal static int DetailCodeFromShutdownReason(ApplicationShutdownReason reason) { switch (reason) { case ApplicationShutdownReason.HostingEnvironment: return 0xc352; case ApplicationShutdownReason.ChangeInGlobalAsax: return 0xc353; case ApplicationShutdownReason.ConfigurationChange: return 0xc354; case ApplicationShutdownReason.UnloadAppDomainCalled: return 0xc355; case ApplicationShutdownReason.ChangeInSecurityPolicyFile: return 0xc356; case ApplicationShutdownReason.BinDirChangeOrDirectoryRename: return 0xc357; case ApplicationShutdownReason.BrowsersDirChangeOrDirectoryRename: return 0xc358; case ApplicationShutdownReason.CodeDirChangeOrDirectoryRename: return 0xc359; case ApplicationShutdownReason.ResourcesDirChangeOrDirectoryRename: return 0xc35a; case ApplicationShutdownReason.IdleTimeout: return 0xc35b; case ApplicationShutdownReason.PhysicalApplicationPathChanged: return 0xc35c; case ApplicationShutdownReason.HttpRuntimeClose: return 0xc35d; case ApplicationShutdownReason.InitializationError: return 0xc35e; case ApplicationShutdownReason.MaxRecompilationsReached: return 0xc35f; case ApplicationShutdownReason.BuildManagerChange: return 0xc361; } return 0xc351; }
internal static int DetailCodeFromShutdownReason(ApplicationShutdownReason reason) { switch (reason) { case ApplicationShutdownReason.HostingEnvironment: return(0xc352); case ApplicationShutdownReason.ChangeInGlobalAsax: return(0xc353); case ApplicationShutdownReason.ConfigurationChange: return(0xc354); case ApplicationShutdownReason.UnloadAppDomainCalled: return(0xc355); case ApplicationShutdownReason.ChangeInSecurityPolicyFile: return(0xc356); case ApplicationShutdownReason.BinDirChangeOrDirectoryRename: return(0xc357); case ApplicationShutdownReason.BrowsersDirChangeOrDirectoryRename: return(0xc358); case ApplicationShutdownReason.CodeDirChangeOrDirectoryRename: return(0xc359); case ApplicationShutdownReason.ResourcesDirChangeOrDirectoryRename: return(0xc35a); case ApplicationShutdownReason.IdleTimeout: return(0xc35b); case ApplicationShutdownReason.PhysicalApplicationPathChanged: return(0xc35c); case ApplicationShutdownReason.HttpRuntimeClose: return(0xc35d); case ApplicationShutdownReason.InitializationError: return(0xc35e); case ApplicationShutdownReason.MaxRecompilationsReached: return(0xc35f); case ApplicationShutdownReason.BuildManagerChange: return(0xc361); } return(0xc351); }
/// <summary> /// Stops the host. /// </summary> /// <param name="immediate"></param> public void Stop(bool immediate) { try { HostingEnvironment.UnregisterObject(this); } catch { }; this.webApp?.Dispose(); this.ShutdownReason = HostingEnvironment.ShutdownReason; this.Shutdown?.Invoke(null, EventArgs.Empty); }
public virtual bool IsDuplicate(object obj) { HostEvent hostEvent = obj as HostEvent; if (hostEvent == null) { return(false); // this is not null so they are different } ApplicationInfo applicationInfo1 = ApplicationInfo; ApplicationShutdownReason reason1 = Reason; ApplicationInfo applicationInfo2 = hostEvent.ApplicationInfo; ApplicationShutdownReason reason2 = hostEvent.Reason; return(applicationInfo1 != null && applicationInfo2 != null && applicationInfo1.Id == applicationInfo2.Id && reason1 == reason2); }
/// <summary> /// Stops the host. /// </summary> /// <param name="immediate"></param> public void Stop(bool immediate) { Trace.TraceInformation("Stopping Wisej.Host: Domain={0}, Port={1}, Reason={2}", this.Domain, this.Port, HostingEnvironment.ShutdownReason); try { HostingEnvironment.UnregisterObject(this); } catch { }; this.webApp?.Dispose(); this.ShutdownReason = HostingEnvironment.ShutdownReason; this.Shutdown?.Invoke(null, EventArgs.Empty); }
private void OnFileChanged(object sender, FileSystemEventArgs args) { lock (((ICollection)_watchers).SyncRoot) { if (_appShutdown) { return; } Stop(false); // Disable event raising to avoid concurrent restarts DisableWatchers(); ApplicationShutdownReason reason = ApplicationShutdownReason.None; string name = new DirectoryInfo(args.FullPath).Name; string message = name + " dir change or directory rename"; if (StringUtil.EqualsIgnoreCase(name, "web.config")) { reason = ApplicationShutdownReason.ConfigurationChange; message = "Config file change"; } else if (StringUtil.EqualsIgnoreCase(name, "bin")) { reason = ApplicationShutdownReason.BinDirChangeOrDirectoryRename; } else { reason = ApplicationShutdownReason.ConfigurationChange; } if (args.ChangeType == WatcherChangeTypes.Created) { FluorineRuntime.SetUserForcedShutdown(); } // Restart application FluorineRuntime.ShutdownAppDomain(reason, message); } }
internal void OnAppDomainShutdown(ApplicationInfo applicationInfo, ApplicationShutdownReason reason) { _events.Add(new HostEvent(applicationInfo, reason)); }
void OnAppDomainShutdown (ApplicationShutdownReason reason) { BuildManagerHostUnloadEventHandler eh = events [appDomainShutdownEvent] as BuildManagerHostUnloadEventHandler; if (eh != null) { BuildManagerHostUnloadEventArgs args = new BuildManagerHostUnloadEventArgs (reason); eh (this, args); } }
public HostEvent(ApplicationInfo applicationInfo, ApplicationShutdownReason reason) { _applicationInfo = applicationInfo; _reason = reason; _delayed = false; }
internal void OnAppDomainUnloaded(ApplicationShutdownReason reason) { this._host = null; this._hostCreationException = null; this._reason = reason; this._waitForCallBack = false; ThreadPool.QueueUserWorkItem(this._onAppDomainUnloadedCallback); }
internal void OnAppDomainShutdown(ApplicationShutdownReason reason) { ThreadPool.QueueUserWorkItem(this._onAppDomainShutdown, reason); }
/// <summary> /// Initializes a new instance of the <see cref="ApplicationUnloadEventArgs"/> class. /// </summary> /// <param name="reason">The reason.</param> public ApplicationUnloadEventArgs(ApplicationShutdownReason reason) { _Reason = reason; }
// Called by BuildManagerHost when the ASP appdomain is unloaded internal void OnAppDomainUnloaded(ApplicationShutdownReason reason) { Debug.Trace("CBM", "OnAppDomainUnloaded " + reason.ToString()); _reason = reason; _waitForCallBack = false; // Don't do anything that can be slow here. Instead queue in a worker thread ThreadPool.QueueUserWorkItem(_onAppDomainUnloadedCallback); }
public HostUnloadEventArgs(ApplicationShutdownReason reason) { _reason = reason; }
internal ApplicationRestartEventArgs(ApplicationInfo applicationInfo, ApplicationShutdownReason reason) { _applicationInfo = applicationInfo; _reason = reason; }
internal static bool ShutdownAppDomain(ApplicationShutdownReason reason, string message) { return HttpRuntime.ShutdownAppDomainWithStackTrace(reason, message, (string) null); }
internal void OnAppDomainUnloaded(ApplicationInfo applicationInfo, ApplicationShutdownReason reason) { /* if (reason == ApplicationShutdownReason.ConfigurationChange || reason == ApplicationShutdownReason.BinDirChangeOrDirectoryRename) { //StartApplication(applicationInfo.PhysicalPath); this._events.Add(new HostEvent(applicationInfo, reason)); } */ _events.Add(new HostEvent(applicationInfo, reason)); }
internal static void SetShutdownReason(ApplicationShutdownReason reason, string message) { if (HttpRuntime._theRuntime._shutdownReason == ApplicationShutdownReason.None) HttpRuntime._theRuntime._shutdownReason = reason; HttpRuntime.SetShutdownMessage(message); }
/// ----------------------------------------------------------------------------- /// <summary> /// LogEnd logs the Application Start Event /// </summary> /// <remarks> /// </remarks> /// <history> /// [cnurse] 1/28/2005 Moved back to App_End from Logging Module /// </history> /// ----------------------------------------------------------------------------- public static void LogEnd() { try { ApplicationShutdownReason shutdownReason = HostingEnvironment.ShutdownReason; string shutdownDetail = ""; switch (shutdownReason) { case ApplicationShutdownReason.BinDirChangeOrDirectoryRename: shutdownDetail = "The AppDomain shut down because of a change to the Bin folder or files contained in it."; break; case ApplicationShutdownReason.BrowsersDirChangeOrDirectoryRename: shutdownDetail = "The AppDomain shut down because of a change to the App_Browsers folder or files contained in it."; break; case ApplicationShutdownReason.ChangeInGlobalAsax: shutdownDetail = "The AppDomain shut down because of a change to Global.asax."; break; case ApplicationShutdownReason.ChangeInSecurityPolicyFile: shutdownDetail = "The AppDomain shut down because of a change in the code access security policy file."; break; case ApplicationShutdownReason.CodeDirChangeOrDirectoryRename: shutdownDetail = "The AppDomain shut down because of a change to the App_Code folder or files contained in it."; break; case ApplicationShutdownReason.ConfigurationChange: shutdownDetail = "The AppDomain shut down because of a change to the application level configuration."; break; case ApplicationShutdownReason.HostingEnvironment: shutdownDetail = "The AppDomain shut down because of the hosting environment."; break; case ApplicationShutdownReason.HttpRuntimeClose: shutdownDetail = "The AppDomain shut down because of a call to Close."; break; case ApplicationShutdownReason.IdleTimeout: shutdownDetail = "The AppDomain shut down because of the maximum allowed idle time limit."; break; case ApplicationShutdownReason.InitializationError: shutdownDetail = "The AppDomain shut down because of an AppDomain initialization error."; break; case ApplicationShutdownReason.MaxRecompilationsReached: shutdownDetail = "The AppDomain shut down because of the maximum number of dynamic recompiles of resources limit."; break; case ApplicationShutdownReason.PhysicalApplicationPathChanged: shutdownDetail = "The AppDomain shut down because of a change to the physical path for the application."; break; case ApplicationShutdownReason.ResourcesDirChangeOrDirectoryRename: shutdownDetail = "The AppDomain shut down because of a change to the App_GlobalResources folder or files contained in it."; break; case ApplicationShutdownReason.UnloadAppDomainCalled: shutdownDetail = "The AppDomain shut down because of a call to UnloadAppDomain."; break; default: shutdownDetail = "No shutdown reason provided."; break; } var objEv = new EventLogController(); var objEventLogInfo = new LogInfo(); objEventLogInfo.BypassBuffering = true; objEventLogInfo.LogTypeKey = EventLogController.EventLogType.APPLICATION_SHUTTING_DOWN.ToString(); objEventLogInfo.AddProperty("Shutdown Details", shutdownDetail); objEv.AddLog(objEventLogInfo); Logger.InfoFormat("Application shutting down. Reason: {0}", shutdownDetail); } catch (Exception exc) { Exceptions.LogException(exc); } if (Globals.Status != Globals.UpgradeStatus.Install) { //purge log buffer LoggingProvider.Instance().PurgeLogBuffer(); } }
public BuildManagerHostUnloadEventArgs(ApplicationShutdownReason reason) { _reason = reason; }
static internal int DetailCodeFromShutdownReason(ApplicationShutdownReason reason) { switch (reason) { case ApplicationShutdownReason.HostingEnvironment: return WebEventCodes.ApplicationShutdownHostingEnvironment; case ApplicationShutdownReason.ChangeInGlobalAsax: return WebEventCodes.ApplicationShutdownChangeInGlobalAsax; case ApplicationShutdownReason.ConfigurationChange: return WebEventCodes.ApplicationShutdownConfigurationChange; case ApplicationShutdownReason.UnloadAppDomainCalled: return WebEventCodes.ApplicationShutdownUnloadAppDomainCalled; case ApplicationShutdownReason.ChangeInSecurityPolicyFile: return WebEventCodes.ApplicationShutdownChangeInSecurityPolicyFile; case ApplicationShutdownReason.BinDirChangeOrDirectoryRename: return WebEventCodes.ApplicationShutdownBinDirChangeOrDirectoryRename; case ApplicationShutdownReason.BrowsersDirChangeOrDirectoryRename: return WebEventCodes.ApplicationShutdownBrowsersDirChangeOrDirectoryRename; case ApplicationShutdownReason.CodeDirChangeOrDirectoryRename: return WebEventCodes.ApplicationShutdownCodeDirChangeOrDirectoryRename; case ApplicationShutdownReason.ResourcesDirChangeOrDirectoryRename: return WebEventCodes.ApplicationShutdownResourcesDirChangeOrDirectoryRename; case ApplicationShutdownReason.IdleTimeout: return WebEventCodes.ApplicationShutdownIdleTimeout; case ApplicationShutdownReason.PhysicalApplicationPathChanged: return WebEventCodes.ApplicationShutdownPhysicalApplicationPathChanged; case ApplicationShutdownReason.HttpRuntimeClose: return WebEventCodes.ApplicationShutdownHttpRuntimeClose; case ApplicationShutdownReason.InitializationError: return WebEventCodes.ApplicationShutdownInitializationError; case ApplicationShutdownReason.MaxRecompilationsReached: return WebEventCodes.ApplicationShutdownMaxRecompilationsReached; case ApplicationShutdownReason.BuildManagerChange: return WebEventCodes.ApplicationShutdownBuildManagerChange; default: return WebEventCodes.ApplicationShutdownUnknown; } }
internal static bool ShutdownAppDomainWithStackTrace(ApplicationShutdownReason reason, string message, string stackTrace) { HttpRuntime.SetShutdownReason(reason, message); return HttpRuntime.ShutdownAppDomain(stackTrace); }
internal void OnAppDomainShutdown(ApplicationShutdownReason reason) { // Don't do anything that can be slow here. Instead queue in a worker thread ThreadPool.QueueUserWorkItem(_onAppDomainShutdown, reason); }
void OnShutdownCore(ApplicationShutdownReason reason) { #if !SILVERLIGHT var canceled = false; #endif try { #if !SILVERLIGHT if (reason == ApplicationShutdownReason.UserRequest && this.isBootCompleted) { //messaggio per notificare ed eventualmente cancellare var msg = new ApplicationShutdownRequested(reason); var broker = this.GetService <IMessageBroker>(); broker.Dispatch(this, msg); canceled = msg.Cancel; if (canceled) { broker.Broadcast(this, new ApplicationShutdownCanceled(reason)); return; } } #endif this.IsShuttingDown = true; if (this.isBootCompleted) { this.GetService <IMessageBroker>().Broadcast(this, new ApplicationShutdown(reason)); var callbacks = this.ResolveAll <IExpectShutdownCallback>(); if (callbacks != null && callbacks.Any()) { foreach (var cb in callbacks) { cb.OnShutdown(reason); } } } var args = new ApplicationShutdownArgs() { Reason = reason, IsBootCompleted = this.isBootCompleted }; this.OnShutdown(args); if (this.shutdownHandler != null) { this.shutdownHandler(args); } if (this.isBootCompleted) { this.catalog.Dispose(); this.compositionContainer.Dispose(); if (this.serviceProvider is IDisposable) { (( IDisposable )this.serviceProvider).Dispose(); } } #if !SILVERLIGHT if (this.mutex != null) { this.mutex.Dispose(); this.mutex = null; } #endif } finally { #if !SILVERLIGHT if (!canceled && reason != ApplicationShutdownReason.ApplicationRequest) { Application.Current.Shutdown(); } #endif #if !SILVERLIGHT if (!canceled) { this.catalog = null; this.compositionContainer = null; this.serviceProvider = null; RegionService.CurrentService = null; RegionService.Conventions = null; } #else this.catalog = null; this.compositionContainer = null; this.serviceProvider = null; RegionService.CurrentService = null; RegionService.Conventions = null; #endif } }
internal static bool ShutdownAppDomain(ApplicationShutdownReason reason, string message) { return(ShutdownAppDomainWithStackTrace(reason, message, null)); }
public BuildManagerHostUnloadEventArgs(ApplicationShutdownReason reason) { this.reason = reason; }
internal static bool ShutdownAppDomainWithStackTrace(ApplicationShutdownReason reason, string message, string stackTrace) { SetShutdownReason(reason, message); //return ShutdownAppDomain(stackTrace); return(ShutdownAppDomain()); }
/// ----------------------------------------------------------------------------- /// <summary> /// LogEnd logs the Application Start Event /// </summary> /// ----------------------------------------------------------------------------- public static void LogEnd() { try { ApplicationShutdownReason shutdownReason = HostingEnvironment.ShutdownReason; string shutdownDetail; switch (shutdownReason) { case ApplicationShutdownReason.BinDirChangeOrDirectoryRename: shutdownDetail = "The AppDomain shut down because of a change to the Bin folder or files contained in it."; break; case ApplicationShutdownReason.BrowsersDirChangeOrDirectoryRename: shutdownDetail = "The AppDomain shut down because of a change to the App_Browsers folder or files contained in it."; break; case ApplicationShutdownReason.ChangeInGlobalAsax: shutdownDetail = "The AppDomain shut down because of a change to Global.asax."; break; case ApplicationShutdownReason.ChangeInSecurityPolicyFile: shutdownDetail = "The AppDomain shut down because of a change in the code access security policy file."; break; case ApplicationShutdownReason.CodeDirChangeOrDirectoryRename: shutdownDetail = "The AppDomain shut down because of a change to the App_Code folder or files contained in it."; break; case ApplicationShutdownReason.ConfigurationChange: shutdownDetail = "The AppDomain shut down because of a change to the application level configuration."; break; case ApplicationShutdownReason.HostingEnvironment: shutdownDetail = "The AppDomain shut down because of the hosting environment."; break; case ApplicationShutdownReason.HttpRuntimeClose: shutdownDetail = "The AppDomain shut down because of a call to Close."; break; case ApplicationShutdownReason.IdleTimeout: shutdownDetail = "The AppDomain shut down because of the maximum allowed idle time limit."; break; case ApplicationShutdownReason.InitializationError: shutdownDetail = "The AppDomain shut down because of an AppDomain initialization error."; break; case ApplicationShutdownReason.MaxRecompilationsReached: shutdownDetail = "The AppDomain shut down because of the maximum number of dynamic recompiles of resources limit."; break; case ApplicationShutdownReason.PhysicalApplicationPathChanged: shutdownDetail = "The AppDomain shut down because of a change to the physical path for the application."; break; case ApplicationShutdownReason.ResourcesDirChangeOrDirectoryRename: shutdownDetail = "The AppDomain shut down because of a change to the App_GlobalResources folder or files contained in it."; break; case ApplicationShutdownReason.UnloadAppDomainCalled: shutdownDetail = "The AppDomain shut down because of a call to UnloadAppDomain."; break; default: shutdownDetail = "Shutdown reason: " + shutdownReason; break; } var log = new LogInfo { BypassBuffering = true, LogTypeKey = EventLogController.EventLogType.APPLICATION_SHUTTING_DOWN.ToString() }; log.AddProperty("Shutdown Details", shutdownDetail); LogController.Instance.AddLog(log); // enhanced shutdown logging var runtime = typeof(HttpRuntime).InvokeMember("_theRuntime", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.GetField, null, null, null) as HttpRuntime; if (runtime == null) { Logger.InfoFormat("Application shutting down. Reason: {0}", shutdownDetail); } else { var shutDownMessage = runtime.GetType().InvokeMember("_shutDownMessage", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField, null, runtime, null) as string; var shutDownStack = runtime.GetType().InvokeMember("_shutDownStack", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField, null, runtime, null) as string; Logger.Info("Application shutting down. Reason: " + shutdownDetail + Environment.NewLine + "ASP.NET Shutdown Info: " + shutDownMessage + Environment.NewLine + shutDownStack); } } catch (Exception exc) { Exceptions.LogException(exc); } if (Globals.Status != Globals.UpgradeStatus.Install) { //purge log buffer LoggingProvider.Instance().PurgeLogBuffer(); } }
internal void OnAppDomainUnload(object unusedObject, EventArgs unusedEventArgs) { Thread.GetDomain().DomainUnload -= _onAppDomainUnload; _reason = FluorineRuntime.ShutdownReason; _applicationInfo = new ApplicationInfo(HostingEnvironment.ApplicationId, HostingEnvironment.ApplicationVirtualPathObject, HostingEnvironment.ApplicationPhysicalPath); ThreadPool.QueueUserWorkItem(_onAppDomainUnloadedCallback); }