From 076fc4adc63c7a46010a11704cdea0e4c06cdcd3 Mon Sep 17 00:00:00 2001 From: Kang Yu Date: Sat, 13 Apr 2024 23:12:58 -0700 Subject: [PATCH] try solve exception --- .../SystrayShell/HotKey.cs | 21 +++++-------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/Ninjacrab.PersistentWindows.Solution/SystrayShell/HotKey.cs b/Ninjacrab.PersistentWindows.Solution/SystrayShell/HotKey.cs index 36e04a7..eddb645 100644 --- a/Ninjacrab.PersistentWindows.Solution/SystrayShell/HotKey.cs +++ b/Ninjacrab.PersistentWindows.Solution/SystrayShell/HotKey.cs @@ -10,10 +10,11 @@ namespace PersistentWindows.SystrayShell public class HotKeyForm : Form { static HotKeyWindow hkwin = null; + static Thread messageLoop; public static void Start(uint hotkey) { - Thread messageLoop = new Thread(() => + messageLoop = new Thread(() => { hkwin = new HotKeyWindow(hotkey); Application.Run(new HotKeyForm(hotkey)); @@ -58,26 +59,14 @@ namespace PersistentWindows.SystrayShell base.SetVisibleCore(false); } - /* #region IDisposable - public virtual void Dispose(bool disposing) - { - //messageLoop.Abort(); - User32.UnregisterHotKey(this.Handle, 0); - } - - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - ~HotKeyForm() { - Dispose(false); + if (messageLoop.IsAlive) + messageLoop.Abort(); + User32.UnregisterHotKey(this.Handle, 0); } #endregion - */ } }