Skip to content

Commit

Permalink
Fixed #105 - App crashes in the background with `The calling thread m…
Browse files Browse the repository at this point in the history
…ust be STA`
  • Loading branch information
ShankarBUS committed Oct 15, 2020
1 parent 085de8d commit 1063dd4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
25 changes: 14 additions & 11 deletions ModernFlyouts/FlyoutHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 6 additions & 3 deletions ModernFlyouts/JumpListHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand Down

0 comments on commit 1063dd4

Please sign in to comment.