Skip to content

Commit 90ea0ac

Browse files
committed
修改程序关闭时释放资源可能出错的问题
1 parent 8e0d845 commit 90ea0ac

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/ComputerLock/Platforms/HotkeyHook.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ public void Register(int id, Hotkey hotKey)
4747
if (ids.Contains(id))
4848
{
4949
Unregister(id);
50-
ids.Remove(id);
5150
}
5251

5352
var success = WinApi.RegisterHotKey(_nativeWindow.Handle, id, (uint)hotKey.Modifiers, (uint)hotKey.Key);
@@ -71,6 +70,18 @@ public void Unregister(int id)
7170
}
7271
}
7372

73+
/// <summary>
74+
/// 注销所有快捷键
75+
/// </summary>
76+
public void UnregisterAll()
77+
{
78+
foreach (var id in ids)
79+
{
80+
WinApi.UnregisterHotKey(_nativeWindow.Handle, id);
81+
}
82+
ids.Clear();
83+
}
84+
7485
public void Dispose()
7586
{
7687
Dispose(true);
@@ -84,10 +95,7 @@ protected virtual void Dispose(bool disposing)
8495
return;
8596
}
8697

87-
foreach (var id in ids)
88-
{
89-
Unregister(id);
90-
}
98+
UnregisterAll();
9199
_nativeWindow.DestroyHandle();
92100
}
93101

0 commit comments

Comments
 (0)