protected override void OnClosing(CancelEventArgs e) { base.OnClosing(e); if (forceClose) { // Stop listening to clipboard ClipboardMonitor.UnregisterListener(this); return; } // We need to run async stuff before closing, so let's always cancel the close at first. e.Cancel = true; // This method will shutdown the application if the session has been successfully closed. SaveAndClose().Forget(); }