call disposed on viewmodels when exiting Wasabi
MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/CoinJoinTabViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/CoinJoinTabViewModel.cs
@@ -383,8 +383,12 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
set
{
bool changed = _coinsList != value;
- if (_coinsList != null) _coinsList.DequeueCoinsPressed -= CoinsList_DequeueCoinsPressedAsync;
+ if (_coinsList != null)
+ _coinsList.DequeueCoinsPressed -= CoinsList_DequeueCoinsPressedAsync;
+
this.RaiseAndSetIfChanged(ref _coinsList, value);
+
+ if (_coinsList != null)
_coinsList.DequeueCoinsPressed += CoinsList_DequeueCoinsPressedAsync;
}
}
@@ -520,11 +524,17 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
if (!_disposedValue)
{
if (disposing)
+ {
+ if (Global.ChaumianClient != null)
{
Global.ChaumianClient.CoinQueued -= ChaumianClient_CoinQueued;
Global.ChaumianClient.CoinDequeued -= ChaumianClient_CoinDequeued;
Global.ChaumianClient.StateUpdated -= ChaumianClient_StateUpdated;
+ }
+
+ if (_coinsList != null)
_coinsList.DequeueCoinsPressed -= CoinsList_DequeueCoinsPressedAsync;
+
_disposables.Dispose();
CoinsList.Dispose();
}

MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/SendTabViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/SendTabViewModel.cs
@@ -589,8 +589,12 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
set
{
bool changed = _coinList != value;
- if (_coinList != null) _coinList.DequeueCoinsPressed -= CoinsList_DequeueCoinsPressedAsync;
+ if (_coinList != null)
+ _coinList.DequeueCoinsPressed -= CoinsList_DequeueCoinsPressedAsync;
+
this.RaiseAndSetIfChanged(ref _coinList, value);
+
+ if (_coinList != null)
_coinList.DequeueCoinsPressed += CoinsList_DequeueCoinsPressedAsync;
}
}
@@ -889,11 +893,16 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
{
if (disposing)
{
+ if (Global.Synchronizer != null)
Global.Synchronizer.PropertyChanged -= Synchronizer_PropertyChanged;
- CoinList.SelectionChanged -= CoinList_SelectionChanged;
+
+ if (_coinList != null)
+ {
+ _coinList.SelectionChanged -= CoinList_SelectionChanged;
_coinList.DequeueCoinsPressed -= CoinsList_DequeueCoinsPressedAsync;
+ _coinList.Dispose();
+ }
- CoinList.Dispose();
_disposables.Dispose();
}

MODIFY
WalletWasabi.Gui/Program.cs
WalletWasabi.Gui/Program.cs
@@ -65,20 +65,20 @@ namespace WalletWasabi.Gui
}
finally
{
+ MainWindowViewModel.Instance.Dispose();
statusBar?.Dispose();
await Global.DisposeAsync();
-
AppDomain.CurrentDomain.UnhandledException -= CurrentDomain_UnhandledException;
TaskScheduler.UnobservedTaskException -= TaskScheduler_UnobservedTaskException;
}
}
- static void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
+ private static void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
{
Logger.LogWarning(e?.Exception, "UnobservedTaskException");
}
- static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
+ private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
Logger.LogWarning(e?.ExceptionObject as Exception, "UnhandledException");
}

MODIFY
WalletWasabi.Gui/ViewModels/MainWindowViewModel.cs
WalletWasabi.Gui/ViewModels/MainWindowViewModel.cs
@@ -7,12 +7,13 @@ using NBitcoin;
using ReactiveUI;
using System;
using System.Collections.Generic;
+using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WalletWasabi.Gui.ViewModels
{
- public class MainWindowViewModel : ViewModelBase
+ public class MainWindowViewModel : ViewModelBase, IDisposable
{
private ModalDialogViewModelBase _modalDialog;
private bool _canClose = true;
@@ -88,5 +89,39 @@ namespace WalletWasabi.Gui.ViewModels
get { return _canClose; }
set { this.RaiseAndSetIfChanged(ref _canClose, value); }
}
+
+ #region IDisposable Support
+
+ private bool _disposedValue = false; // To detect redundant calls
+
+ protected virtual void Dispose(bool disposing)
+ {
+ if (!_disposedValue)
+ {
+ if (disposing)
+ {
+ foreach (var tab in Shell?.Documents?.OfType<IDisposable>())
+ {
+ tab.Dispose();
+ }
+ }
+
+ // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below.
+ // TODO: set large fields to null.
+
+ _disposedValue = true;
+ }
+ }
+
+ // This code added to correctly implement the disposable pattern.
+ public void Dispose()
+ {
+ // Do not change this code. Put cleanup code in Dispose(bool disposing) above.
+ Dispose(true);
+ // TODO: uncomment the following line if the finalizer is overridden above.
+ // GC.SuppressFinalize(this);
+ }
+
+ #endregion IDisposable Support
}
}

call disposed on viewmodels when exiting Wasabi