From b059f9828595afeb216b0781ac0fb667d2c85e34 Mon Sep 17 00:00:00 2001 From: Campbell Date: Mon, 18 May 2020 20:42:11 +1200 Subject: [PATCH] Fix 8 second UI freeze when changing Windows display scale percentage (#249) * Try modifying existing icon before attempting add * Prevent setting _created to false if already created and Modify fails * Remove variable Co-authored-by: Campbell Harding-Deason --- LibreHardwareMonitor/UI/NotifyIconAdv.cs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/LibreHardwareMonitor/UI/NotifyIconAdv.cs b/LibreHardwareMonitor/UI/NotifyIconAdv.cs index 1164dc7..50c78db 100644 --- a/LibreHardwareMonitor/UI/NotifyIconAdv.cs +++ b/LibreHardwareMonitor/UI/NotifyIconAdv.cs @@ -599,16 +599,23 @@ namespace LibreHardwareMonitor.UI { if (!_created) { - int i = 0; - do + if (NativeMethods.Shell_NotifyIcon(NativeMethods.NotifyIconMessage.Modify, data)) { - _created = NativeMethods.Shell_NotifyIcon(NativeMethods.NotifyIconMessage.Add, data); - if (!_created) + _created = true; + } + else + { + int i = 0; + do { - System.Threading.Thread.Sleep(200); - i++; - } - } while (!_created && i < 40); + _created = NativeMethods.Shell_NotifyIcon(NativeMethods.NotifyIconMessage.Add, data); + if (!_created) + { + System.Threading.Thread.Sleep(200); + i++; + } + } while (!_created && i < 40); + } } else {