Skip to content

Commit b725975

Browse files
committed
Fix environment exit stuck issue
1 parent 2f53a79 commit b725975

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

Flow.Launcher/App.xaml.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,14 @@ protected virtual void Dispose(bool disposing)
304304
return;
305305
}
306306

307+
// If we call Environment.Exit(0), the application dispose will be called before _mainWindow.Close()
308+
// Accessing _mainWindow?.Dispatcher will cause the application stuck
309+
// So here we need to check it and just return so that we will not acees _mainWindow?.Dispatcher
310+
if (!_mainWindow.CanClose)
311+
{
312+
return;
313+
}
314+
307315
_disposed = true;
308316
}
309317

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ namespace Flow.Launcher
3232
{
3333
public partial class MainWindow : IDisposable
3434
{
35+
#region Public Property
36+
37+
// Window Event: Close Event
38+
public bool CanClose { get; set; } = false;
39+
40+
#endregion
41+
3542
#region Private Fields
3643

3744
// Dependency Injection
@@ -45,8 +52,6 @@ public partial class MainWindow : IDisposable
4552
private readonly ContextMenu _contextMenu = new();
4653
private readonly MainViewModel _viewModel;
4754

48-
// Window Event: Close Event
49-
private bool _canClose = false;
5055
// Window Event: Key Event
5156
private bool _isArrowKeyPressed = false;
5257

@@ -279,15 +284,15 @@ private async void OnLoaded(object sender, RoutedEventArgs _)
279284

280285
private async void OnClosing(object sender, CancelEventArgs e)
281286
{
282-
if (!_canClose)
287+
if (!CanClose)
283288
{
284289
_notifyIcon.Visible = false;
285290
App.API.SaveAppAllSettings();
286291
e.Cancel = true;
287292
await PluginManager.DisposePluginsAsync();
288293
Notification.Uninstall();
289294
// After plugins are all disposed, we can close the main window
290-
_canClose = true;
295+
CanClose = true;
291296
// Use this instead of Close() to avoid InvalidOperationException when calling Close() in OnClosing event
292297
Application.Current.Shutdown();
293298
}

0 commit comments

Comments
 (0)