private async Task ClosingAsync() { bool closeApplication = false; try { if (Global.ChaumianClient != null) { Global.ChaumianClient.IsQuitPending = true; // indicate -> do not add any more alices to the coinjoin } if (!MainWindowViewModel.Instance.CanClose) { using (var dialog = new CannotCloseDialogViewModel()) { closeApplication = await MainWindowViewModel.Instance.ShowDialogAsync(dialog); // start the deque process with a dialog } } else { closeApplication = true; } if (closeApplication) { try { Global.UiConfig.WindowState = WindowState; Global.UiConfig.Width = Width; Global.UiConfig.Height = Height; await Global.UiConfig.ToFileAsync(); Logging.Logger.LogInfo <UiConfig>("UiConfig is saved."); } catch (Exception ex) { Logging.Logger.LogWarning <MainWindow>(ex); } Interlocked.Exchange(ref _closingState, 2); //now we can close the app Close(); // start the closing process. Will call MainWindow_ClosingAsync again! } //let's go to finally } catch (Exception ex) { Interlocked.Exchange(ref _closingState, 0); //something happened back to starting point Logging.Logger.LogWarning <MainWindow>(ex); } finally { if (!closeApplication) //we are not closing the application for some reason { Interlocked.Exchange(ref _closingState, 0); if (Global.ChaumianClient != null) { Global.ChaumianClient.IsQuitPending = false; //re-enable enqueuing coins } } } }
private async Task ClosingAsync() { bool closeApplication = false; try { // Indicate -> do not add any more alices to the coinjoin. Global.WalletManager.SignalQuitPending(true); if (!MainWindowViewModel.Instance.CanClose) { var dialog = new CannotCloseDialogViewModel(); closeApplication = await MainWindowViewModel.Instance.ShowDialogAsync(dialog); // start the deque process with a dialog } else { closeApplication = true; } if (closeApplication) { try { if (Global.UiConfig != null) // UiConfig not yet loaded. { Global.UiConfig.WindowState = WindowState; if (WindowState == Avalonia.Controls.WindowState.Normal) { Global.UiConfig.Width = Width; Global.UiConfig.Height = Height; } Global.UiConfig.LastActiveTab = IoC.Get <IShell>().SelectedDocument?.GetType().Name; Global.UiConfig.ToFile(); Logger.LogInfo($"{nameof(Global.UiConfig)} is saved."); } Hide(); var wm = IoC.Get <IShell>().Documents?.OfType <WalletManagerViewModel>().FirstOrDefault(); if (wm is { }) { wm.OnClose(); Logger.LogInfo($"{nameof(WalletManagerViewModel)} closed."); } await Global.DisposeAsync(); } catch (Exception ex) { Logger.LogWarning(ex); } Interlocked.Exchange(ref _closingState, 2); //now we can close the app Close(); // start the closing process. Will call MainWindow_ClosingAsync again! }
private async Task ClosingAsync() { bool closeApplication = false; try { // Indicate -> do not add any more alices to the coinjoin. Global.WalletManager.SignalQuitPending(true); if (!MainWindowViewModel.Instance.CanClose) { var dialog = new CannotCloseDialogViewModel(); closeApplication = await MainWindowViewModel.Instance.ShowDialogAsync(dialog); // start the deque process with a dialog } else { closeApplication = true; } if (closeApplication) { try { if (Global.UiConfig is { }) // UiConfig not yet loaded. { Global.UiConfig.WindowState = WindowState; IDocumentTabViewModel?selectedDocument = IoC.Get <IShell>().SelectedDocument; Global.UiConfig.LastActiveTab = selectedDocument is null ? nameof(HistoryTabViewModel) : selectedDocument.GetType().Name; Global.UiConfig.ToFile(); Logger.LogInfo($"{nameof(Global.UiConfig)} is saved."); } Hide(); var wm = IoC.Get <IShell>().Documents?.OfType <WalletManagerViewModel>().FirstOrDefault(); if (wm is { }) { wm.OnClose(); Logger.LogInfo($"{nameof(WalletManagerViewModel)} closed."); } await Global.DisposeAsync(); }
private async Task ClosingAsync() { bool closeApplication = false; try { if (Global.ChaumianClient != null) { Global.ChaumianClient.IsQuitPending = true; // indicate -> do not add any more alices to the coinjoin } if (!MainWindowViewModel.Instance.CanClose) { var dialog = new CannotCloseDialogViewModel(Global); closeApplication = await MainWindowViewModel.Instance.ShowDialogAsync(dialog); // start the deque process with a dialog } else { closeApplication = true; } if (closeApplication) { try { if (Global.UiConfig != null) // UiConfig not yet loaded. { Global.UiConfig.WindowState = WindowState; Global.UiConfig.Width = Width; Global.UiConfig.Height = Height; await Global.UiConfig.ToFileAsync(); Logger.LogInfo($"{nameof(Global.UiConfig)} is saved."); } Hide(); var wm = IoC.Get <IShell>().Documents?.OfType <WalletManagerViewModel>().FirstOrDefault(); if (wm != null) { wm.OnClose(); Logger.LogInfo($"{nameof(WalletManagerViewModel)} closed, hwi enumeration stopped."); } await Global.DisposeAsync(); } catch (Exception ex) { Logger.LogWarning(ex); } Interlocked.Exchange(ref _closingState, 2); //now we can close the app Close(); // start the closing process. Will call MainWindow_ClosingAsync again! } //let's go to finally } catch (Exception ex) { Interlocked.Exchange(ref _closingState, 0); //something happened back to starting point Logger.LogWarning(ex); } finally { if (!closeApplication) //we are not closing the application for some reason { Interlocked.Exchange(ref _closingState, 0); if (Global.ChaumianClient != null) { Global.ChaumianClient.IsQuitPending = false; //re-enable enqueuing coins } } } }