From 2aeca9c18cb984033704c2c1b487239c664ce7c8 Mon Sep 17 00:00:00 2001 From: Lesueur Benjamin Date: Mon, 8 Apr 2024 11:10:55 +0200 Subject: [PATCH] Migrate to Invoke() (#231) * Change all BeginInvoke to Invoke * for loops should be inside dispatcher, not outside --- .../Controllers/DS4Controller.cs | 6 +- .../Controllers/DualSenseController.cs | 6 +- .../Controllers/IController.xaml.cs | 8 +-- .../Hints/Hint_AMD_IntegerScalingCheck.cs | 2 +- .../Controls/Hints/Hint_CoreIsolationCheck.cs | 2 +- .../Hints/Hint_LegionGoLegionSpace.cs | 4 +- .../Controls/Hints/Hint_MSIClawCenter.cs | 4 +- .../Hints/Hint_RogAllyServiceCheck.cs | 4 +- .../Hints/Hint_SteamNeptuneDesktop.cs | 2 +- .../Controls/Hints/Hint_SteamXboxDrivers.cs | 2 +- HandheldCompanion/Managers/Hotkeys/Hotkey.cs | 14 ++--- HandheldCompanion/Managers/HotkeysManager.cs | 43 ++++++++------ HandheldCompanion/Managers/InputsManager.cs | 18 ++++-- HandheldCompanion/Managers/LayoutManager.cs | 2 +- HandheldCompanion/Misc/PowerProfile.cs | 4 +- HandheldCompanion/UI/UIGamepad.cs | 4 +- .../Pages/PerformancePageViewModel.cs | 8 +-- .../Views/Pages/ControllerPage.xaml.cs | 12 ++-- .../Views/Pages/DevicePage.xaml.cs | 6 +- .../Views/Pages/LayoutPage.xaml.cs | 24 ++++---- .../Views/Pages/NotificationsPage.xaml.cs | 6 +- .../Views/Pages/OverlayPage.xaml.cs | 2 +- .../Pages/Profiles/SettingsMode0.xaml.cs | 21 +++---- .../Pages/Profiles/SettingsMode1.xaml.cs | 12 ++-- .../Views/Pages/SettingsPage.xaml.cs | 4 +- .../Views/QuickPages/QuickDevicePage.xaml.cs | 10 ++-- .../Views/QuickPages/QuickHomePage.xaml.cs | 24 ++++---- .../QuickPages/QuickProfilesPage.xaml.cs | 58 +++++++++---------- .../Views/Windows/MainWindow.xaml.cs | 6 +- .../Views/Windows/OverlayModel.xaml.cs | 4 +- .../Views/Windows/OverlayQuickTools.xaml.cs | 4 +- 31 files changed, 166 insertions(+), 160 deletions(-) diff --git a/HandheldCompanion/Controllers/DS4Controller.cs b/HandheldCompanion/Controllers/DS4Controller.cs index 0c6f6ee8d..bfa1eaea9 100644 --- a/HandheldCompanion/Controllers/DS4Controller.cs +++ b/HandheldCompanion/Controllers/DS4Controller.cs @@ -107,11 +107,7 @@ public override void Unplug() public override void SetLightColor(byte R, byte G, byte B) { - // UI thread - Application.Current.Dispatcher.Invoke(() => - { - JslSetLightColour(UserIndex, CommonUtils.rgb_to_int(R, G, B)); - }); + JslSetLightColour(UserIndex, CommonUtils.rgb_to_int(R, G, B)); } public override string GetGlyph(ButtonFlags button) diff --git a/HandheldCompanion/Controllers/DualSenseController.cs b/HandheldCompanion/Controllers/DualSenseController.cs index b9f7e81b8..6e8e57b1e 100644 --- a/HandheldCompanion/Controllers/DualSenseController.cs +++ b/HandheldCompanion/Controllers/DualSenseController.cs @@ -107,11 +107,7 @@ public override void Unplug() public override void SetLightColor(byte R, byte G, byte B) { - // UI thread - Application.Current.Dispatcher.Invoke(() => - { - JslSetLightColour(UserIndex, CommonUtils.rgb_to_int(R, G, B)); - }); + JslSetLightColour(UserIndex, CommonUtils.rgb_to_int(R, G, B)); } public override string GetGlyph(ButtonFlags button) diff --git a/HandheldCompanion/Controllers/IController.xaml.cs b/HandheldCompanion/Controllers/IController.xaml.cs index e75706444..6c4ac4844 100644 --- a/HandheldCompanion/Controllers/IController.xaml.cs +++ b/HandheldCompanion/Controllers/IController.xaml.cs @@ -172,7 +172,7 @@ protected byte UserIndex private void SetVirtualControllerVisualIndex(int value) { // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { foreach (FrameworkElement frameworkElement in UserIndexPanel.Children) { @@ -335,7 +335,7 @@ protected void UpdateUI() return; // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { // ui_button_hook.Content = IsPlugged ? Properties.Resources.Controller_Disconnect : Properties.Resources.Controller_Connect; ui_button_hide.Content = IsHidden() ? Properties.Resources.Controller_Unhide : Properties.Resources.Controller_Hide; @@ -458,7 +458,7 @@ public virtual void Plug() InjectedButtons.Clear(); // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { ui_button_hook.IsEnabled = false; }); @@ -468,7 +468,7 @@ public virtual void Plug() public virtual void Unplug() { // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { ui_button_hook.IsEnabled = true; }); diff --git a/HandheldCompanion/Controls/Hints/Hint_AMD_IntegerScalingCheck.cs b/HandheldCompanion/Controls/Hints/Hint_AMD_IntegerScalingCheck.cs index bf4de258e..4ea5574c1 100644 --- a/HandheldCompanion/Controls/Hints/Hint_AMD_IntegerScalingCheck.cs +++ b/HandheldCompanion/Controls/Hints/Hint_AMD_IntegerScalingCheck.cs @@ -42,7 +42,7 @@ private void CheckSettings() int EmbeddedIntegerScalingSupport = RegistryUtils.GetInt(@"SYSTEM\ControlSet001\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0000", "DalEmbeddedIntegerScalingSupport"); // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { this.Visibility = EmbeddedIntegerScalingSupport != 1 ? Visibility.Visible : Visibility.Collapsed; }); diff --git a/HandheldCompanion/Controls/Hints/Hint_CoreIsolationCheck.cs b/HandheldCompanion/Controls/Hints/Hint_CoreIsolationCheck.cs index b6b78234e..fb2b43f9e 100644 --- a/HandheldCompanion/Controls/Hints/Hint_CoreIsolationCheck.cs +++ b/HandheldCompanion/Controls/Hints/Hint_CoreIsolationCheck.cs @@ -59,7 +59,7 @@ private void CheckSettings() VulnerableDriverBlocklistEnable = RegistryUtils.GetBoolean(@"SYSTEM\CurrentControlSet\Control\CI\Config", "VulnerableDriverBlocklistEnable"); // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { this.Visibility = HypervisorEnforcedCodeIntegrityEnabled || VulnerableDriverBlocklistEnable ? Visibility.Visible : Visibility.Collapsed; }); diff --git a/HandheldCompanion/Controls/Hints/Hint_LegionGoLegionSpace.cs b/HandheldCompanion/Controls/Hints/Hint_LegionGoLegionSpace.cs index 4062b7eaf..cc3988931 100644 --- a/HandheldCompanion/Controls/Hints/Hint_LegionGoLegionSpace.cs +++ b/HandheldCompanion/Controls/Hints/Hint_LegionGoLegionSpace.cs @@ -83,7 +83,7 @@ private void ServiceTimer_Elapsed(object? sender, ElapsedEventArgs e) } // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { this.Visibility = anyRunning ? Visibility.Visible : Visibility.Collapsed; }); @@ -121,7 +121,7 @@ protected override void HintActionButton_Click(object sender, RoutedEventArgs e) public override void Stop() { - serviceTimer.Stop(); + serviceTimer?.Stop(); base.Stop(); } } diff --git a/HandheldCompanion/Controls/Hints/Hint_MSIClawCenter.cs b/HandheldCompanion/Controls/Hints/Hint_MSIClawCenter.cs index 2a0ec17c7..b39030c88 100644 --- a/HandheldCompanion/Controls/Hints/Hint_MSIClawCenter.cs +++ b/HandheldCompanion/Controls/Hints/Hint_MSIClawCenter.cs @@ -104,7 +104,7 @@ private void WatcherTimer_Elapsed(object? sender, ElapsedEventArgs e) bool hasProcesses = HasProcesses(); // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { this.Visibility = hasTask || hasProcesses ? Visibility.Visible : Visibility.Collapsed; }); @@ -118,7 +118,7 @@ protected override void HintActionButton_Click(object sender, RoutedEventArgs e) public override void Stop() { - watcherTimer.Stop(); + watcherTimer?.Stop(); base.Stop(); } } diff --git a/HandheldCompanion/Controls/Hints/Hint_RogAllyServiceCheck.cs b/HandheldCompanion/Controls/Hints/Hint_RogAllyServiceCheck.cs index 980934520..c2a1c0cb1 100644 --- a/HandheldCompanion/Controls/Hints/Hint_RogAllyServiceCheck.cs +++ b/HandheldCompanion/Controls/Hints/Hint_RogAllyServiceCheck.cs @@ -77,7 +77,7 @@ private void ServiceTimer_Elapsed(object? sender, ElapsedEventArgs e) } // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { this.Visibility = anyRunning ? Visibility.Visible : Visibility.Collapsed; }); @@ -102,7 +102,7 @@ protected override void HintActionButton_Click(object sender, RoutedEventArgs e) public override void Stop() { - serviceTimer.Stop(); + serviceTimer?.Stop(); base.Stop(); } } diff --git a/HandheldCompanion/Controls/Hints/Hint_SteamNeptuneDesktop.cs b/HandheldCompanion/Controls/Hints/Hint_SteamNeptuneDesktop.cs index 2f3d1aea7..a163d929c 100644 --- a/HandheldCompanion/Controls/Hints/Hint_SteamNeptuneDesktop.cs +++ b/HandheldCompanion/Controls/Hints/Hint_SteamNeptuneDesktop.cs @@ -28,7 +28,7 @@ private void Steam_Updated(PlatformStatus status) bool DesktopProfileApplied = PlatformManager.Steam.HasDesktopProfileApplied(); // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { switch (status) { diff --git a/HandheldCompanion/Controls/Hints/Hint_SteamXboxDrivers.cs b/HandheldCompanion/Controls/Hints/Hint_SteamXboxDrivers.cs index 7772282ea..7676059b3 100644 --- a/HandheldCompanion/Controls/Hints/Hint_SteamXboxDrivers.cs +++ b/HandheldCompanion/Controls/Hints/Hint_SteamXboxDrivers.cs @@ -34,7 +34,7 @@ private void CheckDrivers() bool HasXboxDriversInstalled = PlatformManager.Steam.HasXboxDriversInstalled(); // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { this.Visibility = HasXboxDriversInstalled ? Visibility.Visible : Visibility.Collapsed; }); diff --git a/HandheldCompanion/Managers/Hotkeys/Hotkey.cs b/HandheldCompanion/Managers/Hotkeys/Hotkey.cs index 7bca0fda4..2ae384cf0 100644 --- a/HandheldCompanion/Managers/Hotkeys/Hotkey.cs +++ b/HandheldCompanion/Managers/Hotkeys/Hotkey.cs @@ -185,7 +185,7 @@ public void Draw() private void DrawGlyph() { // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { // update glyphs mainControl.HotkeyIcon.FontFamily = quickControl.QuickIcon.FontFamily = inputsHotkey.fontFamily; @@ -197,7 +197,7 @@ private void DrawGlyph() private void DrawName() { // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { mainControl.HotkeyDesc.Text = inputsHotkey.GetDescription(); mainControl.HotkeyName.Text = quickControl.QuickName.Text = mainControl.HotkeyCustomName.Text = Name; @@ -284,7 +284,7 @@ private bool HasOutput() public void DrawInput() { // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { // mainButton content SimpleStackPanel inputContent = new() @@ -381,7 +381,7 @@ public void DrawInput() private void DrawOutput() { // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { // update button content switch (HasOutput()) @@ -406,7 +406,7 @@ private void DrawOutput() private void DrawPin() { // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { // update pin button switch (IsPinned) @@ -426,7 +426,7 @@ private void DrawPin() private void DrawErase() { // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { // update delete button status mainControl.HotkeyErase.IsEnabled = HasInput() || HasOutput(); @@ -441,7 +441,7 @@ public void Highlight() public void SetToggle(bool toggle) { // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { switch (toggle) { diff --git a/HandheldCompanion/Managers/HotkeysManager.cs b/HandheldCompanion/Managers/HotkeysManager.cs index ede55bb5b..860fe89e5 100644 --- a/HandheldCompanion/Managers/HotkeysManager.cs +++ b/HandheldCompanion/Managers/HotkeysManager.cs @@ -78,14 +78,15 @@ private static void ControllerManager_ControllerPlugged(IController Controller, { // when the target emulated controller is Dualshock // only enable HIDmode switch hotkey when controller is plugged (last stage of HIDmode change in this case) - var targetHIDmode = (HIDmode)SettingsManager.GetInt("HIDmode", true); + HIDmode targetHIDmode = (HIDmode)SettingsManager.GetInt("HIDmode", true); if (targetHIDmode == HIDmode.DualShock4Controller) { - var hotkeys = Hotkeys.Values.Where(item => item.inputsHotkey.Listener.Equals("shortcutChangeHIDMode")).ToList(); - foreach (Hotkey? hotkey in hotkeys) + List hotkeys = Hotkeys.Values.Where(item => item.inputsHotkey.Listener.Equals("shortcutChangeHIDMode")).ToList(); + Application.Current.Dispatcher.Invoke(() => { - Application.Current.Dispatcher.BeginInvoke(() => { hotkey.IsEnabled = !hasProfileHID; }); - } + foreach (Hotkey? hotkey in hotkeys) + hotkey.IsEnabled = !hasProfileHID; + }); } } @@ -93,13 +94,15 @@ private static void ControllerManager_ControllerUnplugged(IController Controller { // when the target emulated controller is Xbox Controller // only enable HIDmode switch hotkey when controller is unplugged (last stage of HIDmode change in this case) - var targetHIDmode = (HIDmode)SettingsManager.GetInt("HIDmode", true); - + HIDmode targetHIDmode = (HIDmode)SettingsManager.GetInt("HIDmode", true); if (targetHIDmode == HIDmode.Xbox360Controller) { List hotkeys = Hotkeys.Values.Where(item => item.inputsHotkey.Listener.Equals("shortcutChangeHIDMode")).ToList(); - foreach (Hotkey? hotkey in hotkeys) - Application.Current.Dispatcher.Invoke(() => { hotkey.IsEnabled = !hasProfileHID; }); + Application.Current.Dispatcher.Invoke(() => + { + foreach (Hotkey? hotkey in hotkeys) + hotkey.IsEnabled = !hasProfileHID; + }); } } @@ -128,8 +131,11 @@ private static void ProfileManager_Applied(Profile profile, UpdateSource source) // enable/disable hotkey based on profile HIDmode List hotkeys = Hotkeys.Values.Where(item => item.inputsHotkey.Listener.Equals("shortcutChangeHIDMode")).ToList(); - foreach (Hotkey? hotkey in hotkeys) - Application.Current.Dispatcher.Invoke(() => { hotkey.IsEnabled = !hasProfileHID; }); + Application.Current.Dispatcher.Invoke(() => + { + foreach (Hotkey? hotkey in hotkeys) + hotkey.IsEnabled = !hasProfileHID; + }); // change glyph at startup only if (!IsInitialized) @@ -306,17 +312,16 @@ private static int CountPinned() private static void TriggerUpdated(string listener, InputsChord inputs, ListenerType type) { IEnumerable hotkeys = Hotkeys.Values.Where(item => item.inputsHotkey.Listener.Equals(listener)).ToList(); - foreach (Hotkey hotkey in hotkeys) + + Application.Current.Dispatcher.Invoke(() => { - // UI thread - Application.Current.Dispatcher.Invoke(() => + foreach (Hotkey hotkey in hotkeys) { // stop recording and update UI hotkey.StopListening(inputs, type); - }); - - SerializeHotkey(hotkey, true); - } + SerializeHotkey(hotkey, true); + } + }); } private static Hotkey ProcessHotkey(string fileName) @@ -356,7 +361,7 @@ public static void TriggerRaised(string listener, InputsChord input, InputsHotke List hotkeys = Hotkeys.Values.Where(item => item.inputsChord.State.Equals(input.State) && (item.inputsHotkey.OnKeyDown == IsKeyDown || item.inputsHotkey.OnKeyUp == IsKeyUp)).ToList(); // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { foreach (Hotkey hotkey in hotkeys) hotkey.Highlight(); diff --git a/HandheldCompanion/Managers/InputsManager.cs b/HandheldCompanion/Managers/InputsManager.cs index cd22f5272..7f402ba6c 100644 --- a/HandheldCompanion/Managers/InputsManager.cs +++ b/HandheldCompanion/Managers/InputsManager.cs @@ -14,6 +14,7 @@ using static HandheldCompanion.Managers.InputsHotkey; using ButtonState = HandheldCompanion.Inputs.ButtonState; using Timer = System.Timers.Timer; +using Application = System.Windows.Application; namespace HandheldCompanion.Managers; @@ -167,13 +168,18 @@ private static bool CheckForSequence(bool IsKeyDown, bool IsKeyUp) InputsChordType inputType = currentChord.InputsType; if ((inputType == InputsChordType.Click && IsKeyUp) || (inputType == InputsChordType.Long && IsKeyDown)) { - var hidHotkeys = HotkeysManager.Hotkeys.Values.Where(item => item.inputsHotkey.Listener.Equals("shortcutChangeHIDMode")); - foreach (var hidHotkey in hidHotkeys) + List hidHotkeys = HotkeysManager.Hotkeys.Values.Where(item => item.inputsHotkey.Listener.Equals("shortcutChangeHIDMode")).ToList(); + + Application.Current.Dispatcher.Invoke(() => { - if (!hidHotkey.IsEnabled) - return false; - System.Windows.Application.Current.Dispatcher.Invoke(() => { hidHotkey.IsEnabled = false; }); - } + foreach (Hotkey hidHotkey in hidHotkeys) + { + if (!hidHotkey.IsEnabled) + continue; + + hidHotkey.IsEnabled = false; + } + }); } } diff --git a/HandheldCompanion/Managers/LayoutManager.cs b/HandheldCompanion/Managers/LayoutManager.cs index b21fa5beb..b5ce4326e 100644 --- a/HandheldCompanion/Managers/LayoutManager.cs +++ b/HandheldCompanion/Managers/LayoutManager.cs @@ -114,7 +114,7 @@ public static void Stop() private static void LayoutWatcher_Template(object sender, FileSystemEventArgs e) { // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { ProcessLayoutTemplate(e.FullPath); }); diff --git a/HandheldCompanion/Misc/PowerProfile.cs b/HandheldCompanion/Misc/PowerProfile.cs index 41e2db119..be84ac5f9 100644 --- a/HandheldCompanion/Misc/PowerProfile.cs +++ b/HandheldCompanion/Misc/PowerProfile.cs @@ -26,7 +26,7 @@ public string Name _Name = value; // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { foreach (UIElement uIElement in uIElements.Values) uIElement.textBlock1.Text = value; @@ -46,7 +46,7 @@ public string Description _Description = value; // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { foreach (UIElement uIElement in uIElements.Values) uIElement.textBlock2.Text = value; diff --git a/HandheldCompanion/UI/UIGamepad.cs b/HandheldCompanion/UI/UIGamepad.cs index 7dabbdcb1..32902f3d9 100644 --- a/HandheldCompanion/UI/UIGamepad.cs +++ b/HandheldCompanion/UI/UIGamepad.cs @@ -173,7 +173,7 @@ private void _gamepadFrame_ContentRendered(object? sender, EventArgs e) private void _gamepadFrame_PageRendered(object? sender, System.Timers.ElapsedEventArgs e) { // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { // specific-cases switch (_gamepadPage.Tag) @@ -400,7 +400,7 @@ private void InputsUpdated(ControllerState controllerState) } // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { // get current focused element Control focusedElement = FocusedElement(_currentWindow); diff --git a/HandheldCompanion/ViewModels/Pages/PerformancePageViewModel.cs b/HandheldCompanion/ViewModels/Pages/PerformancePageViewModel.cs index 3eb255cdf..58acc7b52 100644 --- a/HandheldCompanion/ViewModels/Pages/PerformancePageViewModel.cs +++ b/HandheldCompanion/ViewModels/Pages/PerformancePageViewModel.cs @@ -498,7 +498,7 @@ public PerformancePageViewModel(bool isQuickTools) // TODO: Get rid of UI update here of fan graph UI dependency if(!IsQuickTools) { - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { _updatingFanCurveUI = true; // update charts @@ -605,7 +605,7 @@ public PerformancePageViewModel(bool isQuickTools) FanPresetSilentCommand = new DelegateCommand(() => { - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { // update charts for (int idx = 0; idx < _fanGraphLineSeries.ActualValues.Count; idx++) @@ -618,7 +618,7 @@ public PerformancePageViewModel(bool isQuickTools) FanPresetPerformanceCommand = new DelegateCommand(() => { - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { // update charts for (int idx = 0; idx < _fanGraphLineSeries.ActualValues.Count; idx++) @@ -631,7 +631,7 @@ public PerformancePageViewModel(bool isQuickTools) FanPresetTurboCommand = new DelegateCommand(() => { - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { // update charts for (int idx = 0; idx < _fanGraphLineSeries.ActualValues.Count; idx++) diff --git a/HandheldCompanion/Views/Pages/ControllerPage.xaml.cs b/HandheldCompanion/Views/Pages/ControllerPage.xaml.cs index ebd24fa21..bee5154c9 100644 --- a/HandheldCompanion/Views/Pages/ControllerPage.xaml.cs +++ b/HandheldCompanion/Views/Pages/ControllerPage.xaml.cs @@ -44,7 +44,7 @@ public ControllerPage(string Tag) : this() private void ProfileManager_Applied(Profile profile, UpdateSource source) { // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { // disable emulated controller combobox if profile is not default or set to default controller if (!profile.Default && (HIDmode)profile.HID != HIDmode.NotSelected) @@ -109,7 +109,7 @@ public void Page_Closed() private void ControllerUnplugged(IController Controller, bool IsPowerCycling, bool WasTarget) { // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { SimpleStackPanel targetPanel = Controller.IsVirtual() ? VirtualDevices : PhysicalDevices; @@ -133,7 +133,7 @@ private void ControllerUnplugged(IController Controller, bool IsPowerCycling, bo private void ControllerPlugged(IController Controller, bool IsPowerCycling) { // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { SimpleStackPanel targetPanel = Controller.IsVirtual() ? VirtualDevices : PhysicalDevices; @@ -165,7 +165,7 @@ private void ControllerManager_ControllerSelected(IController Controller) private void ControllerManager_Working(int status) { // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(async () => + Application.Current.Dispatcher.Invoke(async () => { // status: 0:wip, 1:sucess, 2:failed switch (status) @@ -221,7 +221,7 @@ private void VirtualManager_ControllerSelected(HIDmode mode) return; // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { cB_HidMode.SelectedIndex = (int)mode; }); @@ -260,7 +260,7 @@ private void ControllerRefresh() bool isMuted = SettingsManager.GetBoolean("SteamControllerMute"); // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { PhysicalDevices.Visibility = hasPhysical ? Visibility.Visible : Visibility.Collapsed; WarningNoPhysical.Visibility = !hasPhysical ? Visibility.Visible : Visibility.Collapsed; diff --git a/HandheldCompanion/Views/Pages/DevicePage.xaml.cs b/HandheldCompanion/Views/Pages/DevicePage.xaml.cs index 916e247f5..73d934c8a 100644 --- a/HandheldCompanion/Views/Pages/DevicePage.xaml.cs +++ b/HandheldCompanion/Views/Pages/DevicePage.xaml.cs @@ -67,7 +67,7 @@ private void GenericDeviceUpdated(PnPDevice device, DeviceEventArgs obj) private void ControllerManager_ControllerSelected(IController Controller) { // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { SensorController.IsEnabled = Controller.Capabilities.HasFlag(ControllerCapabilities.MotionSensor); }); @@ -208,7 +208,7 @@ private void SettingsManager_SettingValueChanged(string? name, object value) public void UpdateDevice(PnPDevice device = null) { // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { SensorInternal.IsEnabled = IDevice.GetCurrent().Capabilities.HasFlag(DeviceCapabilities.InternalSensor); SensorExternal.IsEnabled = IDevice.GetCurrent().Capabilities.HasFlag(DeviceCapabilities.ExternalSensor); @@ -218,7 +218,7 @@ public void UpdateDevice(PnPDevice device = null) private void OnColorValuesChanged(UISettings sender, object args) { // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { if (MatchAccentColor.IsOn) SetAccentColor(); diff --git a/HandheldCompanion/Views/Pages/LayoutPage.xaml.cs b/HandheldCompanion/Views/Pages/LayoutPage.xaml.cs index 87b28a1c5..ab1b577b9 100644 --- a/HandheldCompanion/Views/Pages/LayoutPage.xaml.cs +++ b/HandheldCompanion/Views/Pages/LayoutPage.xaml.cs @@ -101,7 +101,7 @@ private void ProfileManager_Updated(Profile profile, UpdateSource source, bool i if (!MainWindow.CurrentPageName.Equals("LayoutPage")) return; - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { switch (source) { @@ -118,7 +118,7 @@ private void ProfileManager_Updated(Profile profile, UpdateSource source, bool i private void ControllerManager_ControllerSelected(IController controller) { // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { RefreshLayoutList(); @@ -142,7 +142,7 @@ private void DeviceManager_UsbDeviceUpdated(PnPDevice device, DeviceEventArgs ob private void LayoutManager_Initialized() { // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { RefreshLayoutList(); }); @@ -151,7 +151,7 @@ private void LayoutManager_Initialized() private void LayoutManager_Updated(LayoutTemplate layoutTemplate) { // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { // Get template separator index var idx = -1; @@ -269,13 +269,13 @@ public void UpdateLayoutTemplate(LayoutTemplate layoutTemplate) private void UpdatePages() { - // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + // This is a very important lock, it blocks backward events to the layout when + // this is actually the backend that triggered the update. Notifications on higher + // levels (pages and mappings) could potentially be blocked for optimization. + using (new ScopedLock(updateLock)) { - // This is a very important lock, it blocks backward events to the layout when - // this is actually the backend that triggered the update. Notifications on higher - // levels (pages and mappings) could potentially be blocked for optimization. - using (new ScopedLock(updateLock)) + // UI thread (async) + Application.Current.Dispatcher.Invoke(() => { // Invoke Layout Updated to trigger ViewModel updates LayoutUpdated?.Invoke(currentTemplate.Layout); @@ -285,8 +285,8 @@ private void UpdatePages() CheckBoxDefaultLayout.IsChecked = currentTemplate.Layout.IsDefaultLayout; CheckBoxDefaultLayout.IsEnabled = currentTemplate.Layout != LayoutManager.GetDesktop(); - } - }); + }); + } } private void cB_Layouts_SizeChanged(object sender, SizeChangedEventArgs e) diff --git a/HandheldCompanion/Views/Pages/NotificationsPage.xaml.cs b/HandheldCompanion/Views/Pages/NotificationsPage.xaml.cs index fc4157cac..a0fdadb86 100644 --- a/HandheldCompanion/Views/Pages/NotificationsPage.xaml.cs +++ b/HandheldCompanion/Views/Pages/NotificationsPage.xaml.cs @@ -35,7 +35,7 @@ public NotificationsPage(string Tag) : this() private void Timer_Elapsed(object? sender, ElapsedEventArgs e) { // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { bool hasAnyVisible = Notifications.Children.OfType().Any(element => element.Visibility == Visibility.Visible); NothingToSee.Visibility = hasAnyVisible ? Visibility.Collapsed : Visibility.Visible; @@ -56,11 +56,11 @@ private void Page_Loaded(object sender, RoutedEventArgs e) public void Page_Closed() { // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { IEnumerable notifications = Notifications.Children.OfType(); foreach(IHint hint in notifications) - hint.Stop(); + hint?.Stop(); }); } diff --git a/HandheldCompanion/Views/Pages/OverlayPage.xaml.cs b/HandheldCompanion/Views/Pages/OverlayPage.xaml.cs index fddbe99cc..243798961 100644 --- a/HandheldCompanion/Views/Pages/OverlayPage.xaml.cs +++ b/HandheldCompanion/Views/Pages/OverlayPage.xaml.cs @@ -37,7 +37,7 @@ public OverlayPage(string Tag) : this() private void RTSS_Updated(PlatformStatus status) { // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { switch (status) { diff --git a/HandheldCompanion/Views/Pages/Profiles/SettingsMode0.xaml.cs b/HandheldCompanion/Views/Pages/Profiles/SettingsMode0.xaml.cs index 08ffebad4..eda3b3fc7 100644 --- a/HandheldCompanion/Views/Pages/Profiles/SettingsMode0.xaml.cs +++ b/HandheldCompanion/Views/Pages/Profiles/SettingsMode0.xaml.cs @@ -4,6 +4,7 @@ using HandheldCompanion.Sensors; using HandheldCompanion.Utils; using System; +using System.Collections.Generic; using System.Numerics; using System.Windows; using System.Windows.Controls; @@ -38,10 +39,10 @@ public SettingsMode0(string Tag) : this() public void SetProfile() { - // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + using (new ScopedLock(updateLock)) { - using (new ScopedLock(updateLock)) + // UI thread (async) + Application.Current.Dispatcher.Invoke(() => { SliderSensitivityX.Value = ProfilesPage.selectedProfile.MotionSensivityX; SliderSensitivityY.Value = ProfilesPage.selectedProfile.MotionSensivityY; @@ -56,14 +57,14 @@ public void SetProfile() // temp StackCurve.Children.Clear(); - foreach (var elem in ProfilesPage.selectedProfile.MotionSensivityArray) + foreach (KeyValuePair elem in ProfilesPage.selectedProfile.MotionSensivityArray) { // skip first item ? if (elem.Key == 0) continue; - var height = elem.Value * StackCurve.Height; - var thumb = new Thumb + double height = elem.Value * StackCurve.Height; + Thumb thumb = new Thumb { Tag = elem.Key, Width = 8, @@ -78,8 +79,8 @@ public void SetProfile() StackCurve.Children.Add(thumb); } - } - }); + }); + } } private void Page_Loaded(object sender, RoutedEventArgs e) @@ -122,13 +123,13 @@ private void SliderSensitivityY_ValueChanged(object sender, RoutedPropertyChange private void Highlight_Thumb(float value) { // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { double dist_x = value / IDevice.GetCurrent().GamepadMotion.GetCalibration().GetGyroThreshold(); foreach (Control control in StackCurve.Children) { - var x = (double)control.Tag; + double x = (double)control.Tag; if (dist_x > x) control.BorderThickness = new Thickness(0, 0, 0, 20); diff --git a/HandheldCompanion/Views/Pages/Profiles/SettingsMode1.xaml.cs b/HandheldCompanion/Views/Pages/Profiles/SettingsMode1.xaml.cs index 0aaf1f7c5..960badc59 100644 --- a/HandheldCompanion/Views/Pages/Profiles/SettingsMode1.xaml.cs +++ b/HandheldCompanion/Views/Pages/Profiles/SettingsMode1.xaml.cs @@ -44,18 +44,18 @@ public SettingsMode1(string Tag) : this() public void SetProfile() { - // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + using (new ScopedLock(updateLock)) { - using (new ScopedLock(updateLock)) + // UI thread (async) + Application.Current.Dispatcher.Invoke(() => { SliderDeadzoneAngle.Value = ProfilesPage.selectedProfile.SteeringDeadzone; SliderPower.Value = ProfilesPage.selectedProfile.SteeringPower; SliderSteeringAngle.Value = ProfilesPage.selectedProfile.SteeringMaxAngle; lvLineSeriesValues.Values = GeneratePoints(ProfilesPage.selectedProfile.SteeringPower); - } - }); + }); + } } private void Page_Loaded(object sender, RoutedEventArgs e) @@ -74,7 +74,7 @@ private void MotionManager_SettingsMode1Update(Vector2 deviceAngle) private void Rotate_Needle(float y) { // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => { lvAngularGauge.Value = y; }); + Application.Current.Dispatcher.Invoke(() => { lvAngularGauge.Value = y; }); } private void SliderSteeringAngle_ValueChanged(object sender, RoutedPropertyChangedEventArgs e) diff --git a/HandheldCompanion/Views/Pages/SettingsPage.xaml.cs b/HandheldCompanion/Views/Pages/SettingsPage.xaml.cs index 2c4709f7d..a481b6a24 100644 --- a/HandheldCompanion/Views/Pages/SettingsPage.xaml.cs +++ b/HandheldCompanion/Views/Pages/SettingsPage.xaml.cs @@ -63,7 +63,7 @@ public SettingsPage(string? Tag) : this() private void RTSS_Updated(PlatformStatus status) { // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { switch (status) { @@ -226,7 +226,7 @@ private void Button_DetectNativeDisplayOrientation_Click(object sender, RoutedEv private void UpdateManager_Updated(UpdateStatus status, UpdateFile updateFile, object value) { // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { switch (status) { diff --git a/HandheldCompanion/Views/QuickPages/QuickDevicePage.xaml.cs b/HandheldCompanion/Views/QuickPages/QuickDevicePage.xaml.cs index 6191a4a80..267012638 100644 --- a/HandheldCompanion/Views/QuickPages/QuickDevicePage.xaml.cs +++ b/HandheldCompanion/Views/QuickPages/QuickDevicePage.xaml.cs @@ -68,7 +68,7 @@ private void ProfileManager_Applied(Profile profile, UpdateSource source) else { // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { // Revert back to resolution in device settings SetResolution(); @@ -76,7 +76,7 @@ private void ProfileManager_Applied(Profile profile, UpdateSource source) } // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { var canChangeDisplay = !profile.IntegerScalingEnabled; DisplayStack.IsEnabled = canChangeDisplay; @@ -88,7 +88,7 @@ private void ProfileManager_Applied(Profile profile, UpdateSource source) private void ProfileManager_Discarded(Profile profile) { // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { SetResolution(); @@ -103,7 +103,7 @@ private void ProfileManager_Discarded(Profile profile) private void NightLight_Toggled(bool enabled) { // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { NightLightToggle.IsOn = enabled; }); @@ -134,7 +134,7 @@ private void RadioTimer_Elapsed(object? sender, ElapsedEventArgs e) radios = await Radio.GetRadiosAsync(); // UI thread (async) - _ = Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { // WIFI WifiToggle.IsEnabled = radios.Where(radio => radio.Kind == RadioKind.WiFi).Any(); diff --git a/HandheldCompanion/Views/QuickPages/QuickHomePage.xaml.cs b/HandheldCompanion/Views/QuickPages/QuickHomePage.xaml.cs index 6bfcbf6f5..ac6592e32 100644 --- a/HandheldCompanion/Views/QuickPages/QuickHomePage.xaml.cs +++ b/HandheldCompanion/Views/QuickPages/QuickHomePage.xaml.cs @@ -77,7 +77,7 @@ private void QuickButton_Click(object sender, RoutedEventArgs e) private void SystemManager_Initialized() { // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { if (MultimediaManager.HasBrightnessSupport()) { @@ -96,25 +96,27 @@ private void SystemManager_Initialized() private void SystemManager_BrightnessNotification(int brightness) { - // UI thread - Application.Current.Dispatcher.Invoke(() => + using (new ScopedLock(brightnessLock)) { - using (new ScopedLock(brightnessLock)) + // UI thread + Application.Current.Dispatcher.Invoke(() => + { SliderBrightness.Value = brightness; - }); + }); + } } private void SystemManager_VolumeNotification(float volume) { - // UI thread - Application.Current.Dispatcher.Invoke(() => + using (new ScopedLock(volumeLock)) { - using (new ScopedLock(volumeLock)) + // UI thread + Application.Current.Dispatcher.Invoke(() => { UpdateVolumeIcon(volume); SliderVolume.Value = Math.Round(volume); - } - }); + }); + } } private void SliderBrightness_ValueChanged(object sender, RoutedPropertyChangedEventArgs e) @@ -144,7 +146,7 @@ private void SliderVolume_ValueChanged(object sender, RoutedPropertyChangedEvent private void ProfileManager_Applied(Profile profile, UpdateSource source) { // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { t_CurrentProfile.Text = profile.ToString(); }); diff --git a/HandheldCompanion/Views/QuickPages/QuickProfilesPage.xaml.cs b/HandheldCompanion/Views/QuickPages/QuickProfilesPage.xaml.cs index 8708aab4c..36ac46b76 100644 --- a/HandheldCompanion/Views/QuickPages/QuickProfilesPage.xaml.cs +++ b/HandheldCompanion/Views/QuickPages/QuickProfilesPage.xaml.cs @@ -134,7 +134,7 @@ public QuickProfilesPage() private void MultimediaManager_Initialized() { // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { DesktopScreen desktopScreen = MultimediaManager.GetDesktopScreen(); desktopScreen.screenDividers.ForEach(d => IntegerScalingComboBox.Items.Add(d)); @@ -159,7 +159,7 @@ private void GPUManager_Hooked(GPU GPU) bool IsGPUScalingEnabled = GPU.GetGPUScaling(); // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { // GPU-specific settings StackProfileRSR.Visibility = GPU is AMDGPU ? Visibility.Visible : Visibility.Collapsed; @@ -182,7 +182,7 @@ private void GPUManager_Unhooked(GPU GPU) GPU.GPUScalingChanged -= OnGPUScalingChanged; // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { StackProfileRSR.IsEnabled = false; StackProfileIS.IsEnabled = false; @@ -193,20 +193,20 @@ private void GPUManager_Unhooked(GPU GPU) private void OnRSRStateChanged(bool Supported, bool Enabled, int Sharpness) { - // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + using (new ScopedLock(updateLock)) { - using (new ScopedLock(updateLock)) + // UI thread (async) + Application.Current.Dispatcher.Invoke(() => { StackProfileRSR.IsEnabled = Supported; - } - }); + }); + } } private void OnGPUScalingChanged(bool Supported, bool Enabled, int Mode) { // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(async () => + Application.Current.Dispatcher.Invoke(() => { using (new ScopedLock(updateLock)) { @@ -220,20 +220,20 @@ private void OnGPUScalingChanged(bool Supported, bool Enabled, int Mode) private void OnIntegerScalingChanged(bool Supported, bool Enabled) { - // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + using (new ScopedLock(updateLock)) { - using (new ScopedLock(updateLock)) + // UI thread (async) + Application.Current.Dispatcher.Invoke(() => { StackProfileIS.IsEnabled = Supported; - } - }); + }); + } } private void RTSS_Updated(PlatformStatus status) { // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { switch (status) { @@ -257,7 +257,7 @@ private void MultimediaManager_DisplaySettingsChanged(DesktopScreen desktopScree List frameLimits = desktopScreen.GetFramelimits(); // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { cB_Framerate.Items.Clear(); @@ -279,7 +279,7 @@ public void SubmitProfile(UpdateSource source = UpdateSource.QuickProfilesPage) private void PowerProfileManager_Deleted(PowerProfile powerProfile) { // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { int idx = -1; foreach (var item in ProfileStack.Children) @@ -318,7 +318,7 @@ private void PowerProfileManager_Deleted(PowerProfile powerProfile) private void PowerProfileManager_Updated(PowerProfile powerProfile, UpdateSource source) { // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { int idx = -1; foreach (var item in ProfileStack.Children) @@ -392,7 +392,7 @@ private void PowerProfile_Selected(PowerProfile powerProfile) return; // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { SelectedPowerProfileName.Text = powerProfile.Name; }); @@ -421,10 +421,10 @@ private void ProfileManager_Applied(Profile profile, UpdateSource source) // update profile selectedProfile = profile; - // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + using (new ScopedLock(updateLock)) { - using (new ScopedLock(updateLock)) + // UI thread (async) + Application.Current.Dispatcher.Invoke(() => { // update profile name CurrentProfileName.Text = selectedProfile.Name; @@ -520,8 +520,8 @@ private void ProfileManager_Applied(Profile profile, UpdateSource source) // RIS RISToggle.IsOn = selectedProfile.RISEnabled; RISSlider.Value = selectedProfile.RISSharpness; - } - }); + }); + } } private void ProfileManager_Deleted(Profile profile) @@ -539,10 +539,10 @@ private void ProcessManager_ForegroundChanged(ProcessEx processEx, ProcessEx bac // update real profile realProfile = ProfileManager.GetProfileFromPath(processEx.Path, true); - // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + using (new ScopedLock(updateLock)) { - using (new ScopedLock(updateLock)) + // UI thread (async) + Application.Current.Dispatcher.Invoke(() => { ProfileToggle.IsOn = !realProfile.Default && realProfile.Enabled; ProfileIcon.Source = processEx.ProcessIcon; @@ -565,8 +565,8 @@ private void ProcessManager_ForegroundChanged(ProcessEx processEx, ProcessEx bac ProcessPath.Text = string.Empty; SubProfilesBorder.Visibility = Visibility.Collapsed; } - } - }); + }); + } } private void UpdateProfile() diff --git a/HandheldCompanion/Views/Windows/MainWindow.xaml.cs b/HandheldCompanion/Views/Windows/MainWindow.xaml.cs index 852cbeecf..d16ab15dc 100644 --- a/HandheldCompanion/Views/Windows/MainWindow.xaml.cs +++ b/HandheldCompanion/Views/Windows/MainWindow.xaml.cs @@ -288,7 +288,7 @@ private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref b private void ControllerManager_ControllerSelected(IController Controller) { // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { GamepadUISelectIcon.Glyph = Controller.GetGlyph(ButtonFlags.B1); GamepadUISelectIcon.Foreground = Controller.GetGlyphColor(ButtonFlags.B1); @@ -304,7 +304,7 @@ private void ControllerManager_ControllerSelected(IController Controller) private void GamepadFocusManagerOnFocused(Control control) { // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { // todo : localize me string controlType = control.GetType().Name; @@ -537,7 +537,7 @@ private void NotificationsPage_LayoutUpdated(int status) bool hasNotification = Convert.ToBoolean(status); // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { HasNotifications.Visibility = hasNotification ? Visibility.Visible : Visibility.Collapsed; }); diff --git a/HandheldCompanion/Views/Windows/OverlayModel.xaml.cs b/HandheldCompanion/Views/Windows/OverlayModel.xaml.cs index 12d6f3be3..4dc0aecfe 100644 --- a/HandheldCompanion/Views/Windows/OverlayModel.xaml.cs +++ b/HandheldCompanion/Views/Windows/OverlayModel.xaml.cs @@ -213,7 +213,7 @@ private void DrawModel(object? sender, EventArgs e) HighLightButtons(); // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { // Define transformation group for model var Transform3DGroupModel = new Transform3DGroup(); @@ -355,7 +355,7 @@ private void HighLightButtons() continue; // Execute the following code on the UI thread - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { // Todo, there is a bug here when switching 3D overlay type that // things are checked from a controller that does not exist or opposite diff --git a/HandheldCompanion/Views/Windows/OverlayQuickTools.xaml.cs b/HandheldCompanion/Views/Windows/OverlayQuickTools.xaml.cs index f72711a63..0a9372ee5 100644 --- a/HandheldCompanion/Views/Windows/OverlayQuickTools.xaml.cs +++ b/HandheldCompanion/Views/Windows/OverlayQuickTools.xaml.cs @@ -161,7 +161,7 @@ private void SystemManager_DisplaySettingsChanged(DesktopScreen desktopScreen, S private void UpdateLocation(int QuickToolsLocation) { // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { switch (QuickToolsLocation) { @@ -191,7 +191,7 @@ private void UpdateLocation(int QuickToolsLocation) private void PowerManager_PowerStatusChanged(PowerStatus status) { // UI thread (async) - Application.Current.Dispatcher.BeginInvoke(() => + Application.Current.Dispatcher.Invoke(() => { var BatteryLifePercent = (int)Math.Truncate(status.BatteryLifePercent * 100.0f); BatteryIndicatorPercentage.Text = $"{BatteryLifePercent}%";