Move SingleInstanceChecker to program.cs
MODIFY
WalletWasabi.Fluent.Desktop/Program.cs
WalletWasabi.Fluent.Desktop/Program.cs
@@ -16,6 +16,7 @@ using WalletWasabi.Gui.CrashReport;
using WalletWasabi.Gui.ViewModels;
using WalletWasabi.Helpers;
using WalletWasabi.Logging;
+using WalletWasabi.Services;
using WalletWasabi.Services.Terminate;
using WalletWasabi.Wallets;
@@ -30,6 +31,8 @@ namespace WalletWasabi.Fluent.Desktop
private static TerminateService TerminateService = new TerminateService(TerminateApplicationAsync);
+ private static SingleInstanceChecker? SingleInstanceChecker { get; set; }
+
// Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
@@ -41,13 +44,16 @@ namespace WalletWasabi.Fluent.Desktop
try
{
Global = CreateGlobal();
+ SingleInstanceChecker = new SingleInstanceChecker(Global.Network);
+
Locator.CurrentMutable.RegisterConstant(Global);
Locator.CurrentMutable.RegisterConstant(CrashReporter);
- //Platform.BaseDirectory = Path.Combine(Global.DataDir, "Gui");
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
+ SingleInstanceChecker.EnsureSingleOrThrowAsync().GetAwaiter().GetResult();
+
runGui = ProcessCliCommands(args);
if (CrashReporter.IsReport)
@@ -174,6 +180,11 @@ namespace WalletWasabi.Fluent.Desktop
Logger.LogSoftwareStopped("Wasabi GUI");
}
+ if (SingleInstanceChecker is { } single)
+ {
+ await single.DisposeAsync().ConfigureAwait(false);
+ }
+
Logger.LogSoftwareStopped("Wasabi");
}

MODIFY
WalletWasabi.Gui/Global.cs
WalletWasabi.Gui/Global.cs
@@ -105,8 +105,6 @@ namespace WalletWasabi.Gui
BitcoinStore = new BitcoinStore(indexStore, transactionStore, mempoolService, blocks);
- SingleInstanceChecker = new SingleInstanceChecker(Network);
-
WasabiClientFactory wasabiClientFactory = Config.UseTor
? new WasabiClientFactory(Config.TorSocks5EndPoint, backendUriGetter: () => Config.GetCurrentBackendUri())
: new WasabiClientFactory(torEndPoint: null, backendUriGetter: () => Config.GetFallbackBackendUri());
@@ -121,8 +119,6 @@ namespace WalletWasabi.Gui
private CancellationTokenSource StoppingCts { get; }
- private SingleInstanceChecker SingleInstanceChecker { get; }
-
public async Task InitializeNoWalletAsync(TerminateService terminateService)
{
InitializationStarted = true;
@@ -130,8 +126,6 @@ namespace WalletWasabi.Gui
try
{
- await SingleInstanceChecker.EnsureSingleOrThrowAsync().ConfigureAwait(false);
-
cancel.ThrowIfCancellationRequested();
Cache = new MemoryCache(new MemoryCacheOptions
@@ -753,15 +747,6 @@ namespace WalletWasabi.Gui
}
Logger.LogDebug($"Step: {nameof(SingleInstanceChecker)}.", nameof(Global));
-
- try
- {
- await SingleInstanceChecker.DisposeAsync().ConfigureAwait(false);
- }
- catch (Exception ex)
- {
- Logger.LogError($"Error during the disposal of {nameof(SingleInstanceChecker)}: {ex}");
- }
}
catch (Exception ex)
{

Move SingleInstanceChecker to program.cs