Split termination in 2 methods
MODIFY
WalletWasabi.Fluent.Desktop/Program.cs
WalletWasabi.Fluent.Desktop/Program.cs
@@ -25,7 +25,7 @@ public class Program
{
private static Global? Global;
- private static readonly TerminateService TerminateService = new(TerminateApplicationAsync);
+ private static readonly TerminateService TerminateService = new(TerminateApplicationAsync, TerminateApplication);
// Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
@@ -165,7 +165,6 @@ public class Program
/// </summary>
private static async Task TerminateApplicationAsync()
{
- MainViewModel.Instance.ClearStacks();
MainViewModel.Instance.StatusIcon.Dispose();
Logger.LogSoftwareStopped("Wasabi GUI");
@@ -175,6 +174,11 @@ public class Program
}
}
+ private static void TerminateApplication()
+ {
+ MainViewModel.Instance.ClearStacks();
+ }
+
private static void TaskScheduler_UnobservedTaskException(object? sender, UnobservedTaskExceptionEventArgs e)
{
Logger.LogDebug(e.Exception);

MODIFY
WalletWasabi/Services/Terminate/TerminateService.cs
WalletWasabi/Services/Terminate/TerminateService.cs
@@ -14,11 +14,13 @@ public class TerminateService
private const long TerminateStatusInProgress = 1;
private const long TerminateStatusFinished = 2;
private readonly Func<Task> _terminateApplicationAsync;
+ private readonly Action _terminateApplication;
private long _terminateStatus;
- public TerminateService(Func<Task> terminateApplicationAsync)
+ public TerminateService(Func<Task> terminateApplicationAsync, Action terminateApplication)
{
_terminateApplicationAsync = terminateApplicationAsync;
+ _terminateApplication = terminateApplication;
AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;
Console.CancelKeyPress += Console_CancelKeyPress;
AssemblyLoadContext.Default.Unloading += Default_Unloading;
@@ -101,6 +103,8 @@ public class TerminateService
// First caller starts the terminate procedure.
Logger.LogDebug("Start shutting down the application.");
+ _terminateApplication();
+
// Async termination has to be started on another thread otherwise there is a possibility of deadlock.
// We still need to block the caller so Wait applied.
Task.Run(async () =>

Split termination in 2 methods