Start services
MODIFY
WalletWasabi.Gui/Global.cs
WalletWasabi.Gui/Global.cs
@@ -7,6 +7,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
+using System.Threading;
using System.Threading.Tasks;
using WalletWasabi.Crypto;
using WalletWasabi.Helpers;
@@ -120,7 +121,9 @@ namespace WalletWasabi.Gui
Logger.LogInfo("Start synchronizing filters...");
}
- public static void InitializeWalletService(KeyManager keyManager)
+ private static CancellationTokenSource CancelWalletServiceInitialization = null;
+
+ public static async Task InitializeWalletServiceAsync(KeyManager keyManager)
{
ChaumianClient = new CcjClient(Network, BlindingPubKey, keyManager, Config.GetCurrentBackendUri());
WalletService = new WalletService(keyManager, IndexDownloader, ChaumianClient, MemPoolService, Nodes, BlocksDir);
@@ -128,12 +131,19 @@ namespace WalletWasabi.Gui
ChaumianClient.Start();
Logger.LogInfo("Start Chaumian CoinJoin service...");
- //WalletService.InitializeAsync()
- Logger.LogInfo("Start WalletService...");
+ using (CancelWalletServiceInitialization = new CancellationTokenSource())
+ {
+ Logger.LogInfo("Starting WalletService...");
+ await WalletService.InitializeAsync(CancelWalletServiceInitialization.Token);
+ Logger.LogInfo("WalletService started.");
+ }
+ CancelWalletServiceInitialization = null;
}
public static async Task DisposeAsync()
{
+ CancelWalletServiceInitialization?.Cancel();
+
WalletService?.Dispose();
Logger.LogInfo($"{nameof(WalletService)} is stopped.", nameof(Global));
@@ -149,7 +159,7 @@ namespace WalletWasabi.Gui
if (ChaumianClient != null)
{
- ChaumianClient.StopAsync().GetAwaiter().GetResult();
+ await ChaumianClient.StopAsync();
}
Logger.LogInfo($"{nameof(ChaumianClient)} is stopped.", nameof(Global));
}

MODIFY
WalletWasabi.Gui/Tabs/WalletManager/LoadWalletViewModel.cs
WalletWasabi.Gui/Tabs/WalletManager/LoadWalletViewModel.cs
@@ -10,6 +10,7 @@ using WalletWasabi.Gui.ViewModels;
using WalletWasabi.KeyManagement;
using WalletWasabi.Logging;
using WalletWasabi.Services;
+using System.Threading.Tasks;
namespace WalletWasabi.Gui.Tabs.WalletManager
{
@@ -39,7 +40,7 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
? "There is already an open wallet. Restart the application in order to be able to open a different wallet."
: string.Empty);
- LoadCommand = ReactiveCommand.Create(LoadWallet, this.WhenAnyValue(x => x.CanLoadWallet));
+ LoadCommand = ReactiveCommand.Create(LoadWalletAsync, this.WhenAnyValue(x => x.CanLoadWallet));
}
public ObservableCollection<string> Wallets
@@ -93,7 +94,7 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
public ReactiveCommand LoadCommand { get; }
- public void LoadWallet()
+ public async Task LoadWalletAsync()
{
var walletFullPath = Path.Combine(Global.WalletsDir, SelectedWallet + ".json");
if (!File.Exists(walletFullPath))
@@ -106,7 +107,7 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
var keyManager = KeyManager.FromFile(walletFullPath);
- Global.InitializeWalletService(keyManager);
+ await Global.InitializeWalletServiceAsync(keyManager);
// ToDo: Close the Wallet Manager, Open Wallet Explorer tabs
}

Start services