Adjusted shutdown mechanics to not block GUI thread

This commit is contained in:
Justin Swanson 2020-08-08 07:33:36 -05:00
parent 8e0ee257f7
commit a2b900a64f
4 changed files with 12 additions and 12 deletions

View File

@ -212,12 +212,12 @@ namespace Wabbajack
.QueryWhenChanged(query => query.FirstOrDefault()) .QueryWhenChanged(query => query.FirstOrDefault())
.ToGuiProperty(this, nameof(ActiveGlobalUserIntervention)); .ToGuiProperty(this, nameof(ActiveGlobalUserIntervention));
CloseWhenCompleteCommand = ReactiveCommand.Create( CloseWhenCompleteCommand = ReactiveCommand.CreateFromTask(
canExecute: this.WhenAny(x => x.Completed) canExecute: this.WhenAny(x => x.Completed)
.Select(x => x != null), .Select(x => x != null),
execute: () => execute: async () =>
{ {
MWVM.ShutdownApplication(); await MWVM.ShutdownApplication();
}); });
GoToCommand = ReactiveCommand.Create( GoToCommand = ReactiveCommand.Create(

View File

@ -412,12 +412,12 @@ namespace Wabbajack
.QueryWhenChanged(query => query.FirstOrDefault()) .QueryWhenChanged(query => query.FirstOrDefault())
.ToGuiProperty(this, nameof(ActiveGlobalUserIntervention)); .ToGuiProperty(this, nameof(ActiveGlobalUserIntervention));
CloseWhenCompleteCommand = ReactiveCommand.Create( CloseWhenCompleteCommand = ReactiveCommand.CreateFromTask(
canExecute: this.WhenAny(x => x.Completed) canExecute: this.WhenAny(x => x.Completed)
.Select(x => x != null), .Select(x => x != null),
execute: () => execute: async () =>
{ {
MWVM.ShutdownApplication(); await MWVM.ShutdownApplication();
}); });
GoToInstallCommand = ReactiveCommand.Create( GoToInstallCommand = ReactiveCommand.Create(

View File

@ -143,12 +143,12 @@ namespace Wabbajack
.Select(active => !SettingsPane.IsValueCreated || !object.ReferenceEquals(active, SettingsPane.Value)), .Select(active => !SettingsPane.IsValueCreated || !object.ReferenceEquals(active, SettingsPane.Value)),
execute: () => NavigateTo(SettingsPane.Value)); execute: () => NavigateTo(SettingsPane.Value));
OpenTerminalCommand = ReactiveCommand.Create(() => OpenTerminal()); OpenTerminalCommand = ReactiveCommand.CreateFromTask(() => OpenTerminal());
} }
private void OpenTerminal() private async Task OpenTerminal()
{ {
var process = new ProcessStartInfo var process = new ProcessStartInfo
{ {
@ -156,7 +156,7 @@ namespace Wabbajack
WorkingDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) WorkingDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)
}; };
Process.Start(process); Process.Start(process);
ShutdownApplication(); await ShutdownApplication();
} }
private static bool IsStartingFromModlist(out AbsolutePath modlistPath) private static bool IsStartingFromModlist(out AbsolutePath modlistPath)
@ -193,14 +193,14 @@ namespace Wabbajack
ActivePane = vm; ActivePane = vm;
} }
public void ShutdownApplication() public async Task ShutdownApplication()
{ {
Dispose(); Dispose();
Settings.PosX = MainWindow.Left; Settings.PosX = MainWindow.Left;
Settings.PosY = MainWindow.Top; Settings.PosY = MainWindow.Top;
Settings.Width = MainWindow.Width; Settings.Width = MainWindow.Width;
Settings.Height = MainWindow.Height; Settings.Height = MainWindow.Height;
MainSettings.SaveSettings(Settings).AsTask().Wait(); await MainSettings.SaveSettings(Settings);
Application.Current.Shutdown(); Application.Current.Shutdown();
} }
} }

View File

@ -162,7 +162,7 @@ namespace Wabbajack
private void Window_Closing(object sender, CancelEventArgs e) private void Window_Closing(object sender, CancelEventArgs e)
{ {
_mwvm.ShutdownApplication(); _mwvm.ShutdownApplication().Wait();
} }
} }
} }