Trying to dispose mouse hook earlier to potentialy fix the lagging mouse bug after selecting the color (#5530)

This commit is contained in:
martinchrzan 2020-08-15 17:28:53 +02:00 committed by GitHub
parent be36b4aac1
commit 04c80915e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 11 deletions

View File

@ -2,6 +2,7 @@
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
using ColorPicker.Helpers;
using System; using System;
using System.ComponentModel; using System.ComponentModel;
using System.Diagnostics; using System.Diagnostics;
@ -71,7 +72,7 @@ namespace ColorPicker.Mouse
if (!result) if (!result)
{ {
int errorCode = Marshal.GetLastWin32Error(); int errorCode = Marshal.GetLastWin32Error();
throw new Win32Exception(errorCode); Logger.LogError("Failed to unsubscribe mouse hook with the error code" + errorCode);
} }
} }
} }
@ -90,7 +91,7 @@ namespace ColorPicker.Mouse
if (_mouseHookHandle == IntPtr.Zero) if (_mouseHookHandle == IntPtr.Zero)
{ {
int errorCode = Marshal.GetLastWin32Error(); int errorCode = Marshal.GetLastWin32Error();
throw new Win32Exception(errorCode); Logger.LogError("Failed to subscribe mouse hook with the error code" + errorCode);
} }
} }
} }

View File

@ -94,15 +94,7 @@ namespace ColorPicker.Mouse
private void AppStateMonitor_AppClosed(object sender, EventArgs e) private void AppStateMonitor_AppClosed(object sender, EventArgs e)
{ {
_timer.Stop(); DisposeHook();
_previousMousePosition = new System.Windows.Point(-1, 1);
_mouseHook.OnMouseDown -= MouseHook_OnMouseDown;
_mouseHook.OnMouseWheel -= MouseHook_OnMouseWheel;
if (_userSettings.ChangeCursor.Value)
{
CursorManager.RestoreOriginalCursors();
}
} }
private void AppStateMonitor_AppShown(object sender, EventArgs e) private void AppStateMonitor_AppShown(object sender, EventArgs e)
@ -135,7 +127,25 @@ namespace ColorPicker.Mouse
private void MouseHook_OnMouseDown(object sender, Point p) private void MouseHook_OnMouseDown(object sender, Point p)
{ {
DisposeHook();
OnMouseDown?.Invoke(this, p); OnMouseDown?.Invoke(this, p);
} }
private void DisposeHook()
{
if (_timer.IsEnabled)
{
_timer.Stop();
}
_previousMousePosition = new System.Windows.Point(-1, 1);
_mouseHook.OnMouseDown -= MouseHook_OnMouseDown;
_mouseHook.OnMouseWheel -= MouseHook_OnMouseWheel;
if (_userSettings.ChangeCursor.Value)
{
CursorManager.RestoreOriginalCursors();
}
}
} }
} }