From 5b779fb0ece3c1c61be167623cceec21116da5bf Mon Sep 17 00:00:00 2001 From: dlprows Date: Tue, 29 Aug 2023 22:56:52 -0600 Subject: [PATCH] Fix an issue where sometimes the window proc would throw exceptions and crash the plugin --- src/FocusVolumeControl/DialAction.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/FocusVolumeControl/DialAction.cs b/src/FocusVolumeControl/DialAction.cs index da03984..0aa4c54 100644 --- a/src/FocusVolumeControl/DialAction.cs +++ b/src/FocusVolumeControl/DialAction.cs @@ -66,7 +66,6 @@ public class DialAction : EncoderBase _thread.SetApartmentState(ApartmentState.STA); _thread.Start(); - _currentAudioSession = settings.FallbackBehavior == FallbackBehavior.SystemSounds ? _audioHelper.GetSystemSounds() : _audioHelper.GetSystemVolume(); } @@ -207,10 +206,17 @@ public class DialAction : EncoderBase } - public void WinEventProc(IntPtr hWinEventHook, uint eventType, IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime) - { - OnTick(); - } - + public void WinEventProc(IntPtr hWinEventHook, uint eventType, IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime) + { + try + { + OnTick(); + Thread.Sleep(TimeSpan.FromSeconds(1)); + } + catch (Exception ex) + { + Logger.Instance.LogMessage(TracingLevel.ERROR, $"Exception on WinEventProc\n {ex}"); + } + } }