Remove Environment.Exit
MODIFY
WalletWasabi.Fluent.Desktop/Program.cs
WalletWasabi.Fluent.Desktop/Program.cs
@@ -36,8 +36,8 @@ namespace WalletWasabi.Fluent.Desktop
// yet and stuff might break.
public static void Main(string[] args)
{
- bool runGui;
- Exception? appException = null;
+ int exitCode = 0;
+ bool guiStarted = false;
try
{
@@ -53,30 +53,43 @@ namespace WalletWasabi.Fluent.Desktop
SingleInstanceChecker.EnsureSingleOrThrowAsync().GetAwaiter().GetResult();
- runGui = ProcessCliCommands(args);
-
+ if (args.Length != 0)
+ {
+ ProcessCliCommands(args);
+ }
+ else
+ {
if (CrashReporter.IsReport)
{
Console.WriteLine("TODO Implement crash reporting.");
return;
}
- if (runGui)
- {
Logger.LogSoftwareStarted("Wasabi GUI");
-
+ guiStarted = true;
BuildAvaloniaApp()
.AfterSetup(_ => ThemeHelper.ApplyTheme(Global!.UiConfig.DarkModeEnabled))
.StartWithClassicDesktopLifetime(args);
}
}
+ catch (OperationCanceledException ex)
+ {
+ Logger.LogDebug(ex);
+ }
catch (Exception ex)
{
- appException = ex;
- throw;
+ exitCode = 1;
+ Logger.LogCritical(ex);
+
+ if (guiStarted)
+ {
+ CrashReporter.SetException(ex);
}
+ }
+
+ TerminateService.Terminate();
- TerminateAppAndHandleException(appException, runGui);
+ Environment.Exit(exitCode);
}
private static Global CreateGlobal()
@@ -107,27 +120,6 @@ namespace WalletWasabi.Fluent.Desktop
return executionTask.GetAwaiter().GetResult();
}
- /// <summary>
- /// This is a helper method until the creation of the window in AppMainAsync cannot be aborted without Environment.Exit().
- /// </summary>
- private static void TerminateAppAndHandleException(Exception? ex, bool runGui)
- {
- if (ex is OperationCanceledException)
- {
- Logger.LogDebug(ex);
- }
- else if (ex is { })
- {
- Logger.LogCritical(ex);
- if (runGui)
- {
- CrashReporter.SetException(ex);
- }
- }
-
- TerminateService.Terminate(ex is { } ? 1 : 0);
- }
-
/// <summary>
/// Do not call this method it should only be called by TerminateService.
/// </summary>

MODIFY
WalletWasabi.Gui/Program.cs
WalletWasabi.Gui/Program.cs
@@ -119,6 +119,7 @@ namespace WalletWasabi.Gui
{
// There is no other way to stop the creation of the WasabiWindow, we have to exit the application here instead of return to Main.
TerminateAppAndHandleException(ex, true);
+ Environment.Exit(1);
}
}
@@ -140,7 +141,7 @@ namespace WalletWasabi.Gui
}
}
- TerminateService.Terminate(ex is { } ? 1 : 0);
+ TerminateService.Terminate();
}
/// <summary>

MODIFY
WalletWasabi/Services/Terminate/TerminateService.cs
WalletWasabi/Services/Terminate/TerminateService.cs
@@ -78,8 +78,8 @@ namespace WalletWasabi.Services.Terminate
/// <summary>
/// Terminates the application.
/// </summary>
- /// <remark>This is a blocking method. Note that program execution ends at the end of this method due to <see cref="Environment.Exit(int)"/> call.</remark>
- public void Terminate(int exitCode = 0)
+ /// <remark>This is a blocking method.</remark>
+ public void Terminate()
{
var prevValue = Interlocked.CompareExchange(ref _terminateStatus, TerminateStatusInProgress, TerminateStatusNotStarted);
Logger.LogTrace($"Terminate was called from ThreadId: {Thread.CurrentThread.ManagedThreadId}");
@@ -124,8 +124,6 @@ namespace WalletWasabi.Services.Terminate
Interlocked.Exchange(ref _terminateStatus, TerminateStatusFinished);
Logger.LogSoftwareStopped("Wasabi");
-
- Environment.Exit(exitCode);
}
}
}

Remove Environment.Exit