save reference to local variable
MODIFY
WalletWasabi.Gui/Global.cs
WalletWasabi.Gui/Global.cs
@@ -320,9 +320,10 @@ namespace WalletWasabi.Gui
Nodes.Connect();
Logger.LogInfo("Start connecting to nodes...");
- if (RegTestMempoolServingNode != null)
+ var regTestMempoolServingNode = RegTestMempoolServingNode;
+ if (RegTestMempoolServingNode is { })
{
- RegTestMempoolServingNode.VersionHandshake();
+ regTestMempoolServingNode.VersionHandshake();
Logger.LogInfo("Start connecting to mempool serving regtest node...");
}
@@ -576,10 +577,12 @@ namespace WalletWasabi.Gui
public async Task DisposeInWalletDependentServicesAsync()
{
- if (WalletService != null)
+ var walletService = WalletService;
+ if (walletService is { })
{
- WalletService.TransactionProcessor.CoinReceived -= CoinReceived;
+ walletService.TransactionProcessor.CoinReceived -= CoinReceived;
}
+
try
{
_cancelWalletServiceInitialization?.Cancel();
@@ -590,22 +593,25 @@ namespace WalletWasabi.Gui
}
_cancelWalletServiceInitialization = null;
- if (WalletService != null)
+ walletService = WalletService;
+ if (walletService is { })
{
- if (WalletService.KeyManager != null) // This should not ever happen.
+ var keyManager = walletService.KeyManager;
+ if (keyManager is { }) // This should not ever happen.
{
- string backupWalletFilePath = Path.Combine(WalletBackupsDir, Path.GetFileName(WalletService.KeyManager.FilePath));
- WalletService.KeyManager?.ToFile(backupWalletFilePath);
- Logger.LogInfo($"{nameof(KeyManager)} backup saved to `{backupWalletFilePath}`.");
+ string backupWalletFilePath = Path.Combine(WalletBackupsDir, Path.GetFileName(keyManager.FilePath));
+ keyManager.ToFile(backupWalletFilePath);
+ Logger.LogInfo($"{nameof(walletService.KeyManager)} backup saved to `{backupWalletFilePath}`.");
}
- WalletService?.Dispose();
+ walletService?.Dispose();
WalletService = null;
Logger.LogInfo($"{nameof(WalletService)} is stopped.");
}
- if (ChaumianClient != null)
+ var chaumianClient = ChaumianClient;
+ if (chaumianClient is { })
{
- await ChaumianClient.StopAsync();
+ await chaumianClient.StopAsync();
ChaumianClient = null;
Logger.LogInfo($"{nameof(ChaumianClient)} is stopped.");
}
@@ -638,76 +644,87 @@ namespace WalletWasabi.Gui
{
await DisposeInWalletDependentServicesAsync();
- if (UpdateChecker != null)
+ var updateChecker = UpdateChecker;
+ if (updateChecker is { })
{
- await UpdateChecker?.StopAsync();
+ await updateChecker.StopAsync();
Logger.LogInfo($"{nameof(UpdateChecker)} is stopped.");
}
- if (FeeProviders != null)
+ var feeProviders = FeeProviders;
+ if (feeProviders is { })
{
- FeeProviders.Dispose();
+ feeProviders.Dispose();
Logger.LogInfo($"Disposed {nameof(FeeProviders)}.");
}
- if (Synchronizer != null)
+ var synchronizer = Synchronizer;
+ if (synchronizer is { })
{
- await Synchronizer?.StopAsync();
+ await synchronizer.StopAsync();
Logger.LogInfo($"{nameof(Synchronizer)} is stopped.");
}
- if (RpcFeeProvider != null)
+ var rpcFeeProvider = RpcFeeProvider;
+ if (rpcFeeProvider is { })
{
- await RpcFeeProvider.StopAsync();
+ await rpcFeeProvider.StopAsync();
Logger.LogInfo("Stopped synching fees through RPC.");
}
- if (AddressManagerFilePath != null)
+ var addressManagerFilePath = AddressManagerFilePath;
+ if (addressManagerFilePath is { })
{
- IoHelpers.EnsureContainingDirectoryExists(AddressManagerFilePath);
- if (AddressManager != null)
+ IoHelpers.EnsureContainingDirectoryExists(addressManagerFilePath);
+ var addressManager = AddressManager;
+ if (addressManager is { })
{
- AddressManager?.SavePeerFile(AddressManagerFilePath, Config.Network);
+ addressManager.SavePeerFile(AddressManagerFilePath, Config.Network);
Logger.LogInfo($"{nameof(AddressManager)} is saved to `{AddressManagerFilePath}`.");
}
}
- if (Nodes != null)
+ var nodes = Nodes;
+ if (nodes is { })
{
- Nodes?.Disconnect();
- while (Nodes.ConnectedNodes.Any(x => x.IsConnected))
+ nodes.Disconnect();
+ while (nodes.ConnectedNodes.Any(x => x.IsConnected))
{
await Task.Delay(50);
}
- Nodes?.Dispose();
+ nodes.Dispose();
Logger.LogInfo($"{nameof(Nodes)} are disposed.");
}
- if (RegTestMempoolServingNode != null)
+ var regTestMempoolServingNode = RegTestMempoolServingNode;
+ if (regTestMempoolServingNode is { })
{
- RegTestMempoolServingNode.Disconnect();
+ regTestMempoolServingNode.Disconnect();
Logger.LogInfo($"{nameof(RegTestMempoolServingNode)} is disposed.");
}
- if (RpcMonitor != null)
+ var rpcMonitor = RpcMonitor;
+ if (rpcMonitor is { })
{
- await RpcMonitor.StopAsync();
+ await rpcMonitor.StopAsync();
Logger.LogInfo("Stopped monitoring RPC.");
}
- if (BitcoinCoreNode != null)
+ var bitcoinCoreNode = BitcoinCoreNode;
+ if (bitcoinCoreNode is { })
{
- await BitcoinCoreNode.DisposeAsync().ConfigureAwait(false);
+ await bitcoinCoreNode.DisposeAsync().ConfigureAwait(false);
if (Config.StopLocalBitcoinCoreOnShutdown)
{
- await BitcoinCoreNode.TryStopAsync().ConfigureAwait(false);
+ await bitcoinCoreNode.TryStopAsync().ConfigureAwait(false);
}
}
- if (TorManager != null)
+ var torManager = TorManager;
+ if (torManager is { })
{
- await TorManager?.StopAsync();
+ await torManager.StopAsync();
Logger.LogInfo($"{nameof(TorManager)} is stopped.");
}

MODIFY
WalletWasabi/BitcoinCore/CoreNode.cs
WalletWasabi/BitcoinCore/CoreNode.cs
@@ -235,9 +235,10 @@ namespace WalletWasabi.BitcoinCore
{
if (!_disposedValue)
{
- if (BlockNotifier is { })
+ var blockNotifier = BlockNotifier;
+ if (blockNotifier is { })
{
- await BlockNotifier.StopAsync().ConfigureAwait(false);
+ await blockNotifier.StopAsync().ConfigureAwait(false);
}
P2pNode?.Dispose();
_disposedValue = true;

save reference to local variable