/// <summary> /// Called when the application shutdowns. /// </summary> protected virtual void OnShutdown(ApplicationShutdownArgs e) { }
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 } }