public void SuspendExecutors() { _log.Info("SuspendExecutors"); if (OnSuspending != null) { foreach (Action handler in OnSuspending.GetInvocationList()) { handler(); } } }
/// <summary> /// note: Suspending event will not fire during debugging. But sometimes it does. /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private async void SuspendingAsync(object sender, SuspendingEventArgs args) { Debug.LogMessage("App.SuspendingAsync"); // save app state asynchronously after requesting a deferral. Holding a deferral indicates that the application is busy // performing suspending operations. Be aware that a deferral may not be held indefinitely. After about five seconds, // the app will be forced to exit. SuspendingDeferral deferral = args.SuspendingOperation.GetDeferral(); await Task.Run(() => { // stop any running processes... OnSuspending?.Invoke(this, null); }); deferral.Complete(); CoreApplication.Exit(); #if DEBUG System.Diagnostics.Debug.WriteLine("App.SuspendingAsync() complete."); #endif }