From 1063dd4f27318ec0b913a5340ee86b19182b1e71 Mon Sep 17 00:00:00 2001 From: Shankar Date: Thu, 15 Oct 2020 10:01:31 +0530 Subject: [PATCH] Fixed #105 - App crashes in the background with `The calling thread must be STA` --- ModernFlyouts/FlyoutHandler.cs | 25 ++++++++++++++----------- ModernFlyouts/JumpListHelper.cs | 9 ++++++--- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/ModernFlyouts/FlyoutHandler.cs b/ModernFlyouts/FlyoutHandler.cs index 0669f4e7..a29dd0da 100644 --- a/ModernFlyouts/FlyoutHandler.cs +++ b/ModernFlyouts/FlyoutHandler.cs @@ -314,20 +314,23 @@ public static void SafelyExitApplication() public static void ShowSettingsWindow() { - if (Instance.SettingsWindow == null) + App.Current.Dispatcher.Invoke(() => { - Instance.SettingsWindow = new SettingsWindow(); - WindowPlacement.SetPlacement(new WindowInteropHelper(Instance.SettingsWindow).EnsureHandle(), AppDataHelper.SettingsWindowPlacement); - - void handler(object sender, CancelEventArgs e) + if (Instance.SettingsWindow == null) { - Instance.SettingsWindow.Closing -= handler; - AppDataHelper.SettingsWindowPlacement = WindowPlacement.GetPlacement(new WindowInteropHelper(Instance.SettingsWindow).Handle); - Instance.SettingsWindow = null; + Instance.SettingsWindow = new SettingsWindow(); + WindowPlacement.SetPlacement(new WindowInteropHelper(Instance.SettingsWindow).EnsureHandle(), AppDataHelper.SettingsWindowPlacement); + + void handler(object sender, CancelEventArgs e) + { + Instance.SettingsWindow.Closing -= handler; + AppDataHelper.SettingsWindowPlacement = WindowPlacement.GetPlacement(new WindowInteropHelper(Instance.SettingsWindow).Handle); + Instance.SettingsWindow = null; + } + Instance.SettingsWindow.Closing += handler; } - Instance.SettingsWindow.Closing += handler; - } - Instance.SettingsWindow.Show(); + Instance.SettingsWindow.Show(); + }); } public event PropertyChangedEventHandler PropertyChanged; diff --git a/ModernFlyouts/JumpListHelper.cs b/ModernFlyouts/JumpListHelper.cs index e53778cd..0671ba84 100644 --- a/ModernFlyouts/JumpListHelper.cs +++ b/ModernFlyouts/JumpListHelper.cs @@ -22,7 +22,8 @@ public static void CreateJumpList() Title = Properties.Strings.SettingsItem, Description = Properties.Strings.SettingsItemDescription, ApplicationPath = AppPath, - Arguments = arg_settings + Arguments = arg_settings, + IconResourceIndex = -1 }; jumpList.JumpItems.Add(settingsTask); @@ -31,7 +32,8 @@ public static void CreateJumpList() Title = Properties.Strings.RestoreDefaultItem, Description = Properties.Strings.RestoreDefaultItemDescription, ApplicationPath = AppPath, - Arguments = arg_restore + Arguments = arg_restore, + IconResourceIndex = -1, }; jumpList.JumpItems.Add(restoreTask); @@ -40,7 +42,8 @@ public static void CreateJumpList() Title = Properties.Strings.ExitItem, Description = Properties.Strings.ExitItemDescription, ApplicationPath = AppPath, - Arguments = arg_exit + Arguments = arg_exit, + IconResourceIndex = -1 }; jumpList.JumpItems.Add(exitTask);