SocketException when attempting to uninstall keyboard hooks.
tmosson1 opened this issue · 3 comments
Hello,
UPDATE - Modified the description on what code is causing the Socket Exception.
I am really stuck on this one.
I am attempting to use Winook in my .NET Framework 4.8 winform application by mapping hot keys and hot key combinations for a third party document imaging SDK I am using.
I am adding the handlers for my hot keys and hot key combinations as so and then installing them on the main thread by calling a sub procedure.
Process process = Process.GetCurrentProcess();
keyboardHook = new KeyboardHook(process.Id);
keyboardHook.AddHandler(KeyCode.F1, KeyHookCmd);
keyboardHook.AddHandler(KeyCode.F3, KeyHookCmd);
keyboardHook.AddHandler(KeyCode.F4, KeyHookCmd);
keyboardHook.AddHandler(KeyCode.F5, KeyHookCmd);
keyboardHook.AddHandler(KeyCode.F6, KeyHookCmd);
keyboardHook.AddHandler(KeyCode.F7, KeyHookCmd);
keyboardHook.AddHandler(KeyCode.F8, KeyHookCmd);
keyboardHook.AddHandler(KeyCode.F10, KeyHookCmd);
keyboardHook.AddHandler(KeyCode.F11, KeyHookCmd);
keyboardHook.AddHandler(KeyCode.F12, KeyHookCmd);
keyboardHook.AddHandler(KeyCode.P, Modifiers.Control, KeyHookCmd);
keyboardHook.AddHandler(KeyCode.N, Modifiers.Control, KeyHookCmd);
keyboardHook.AddHandler(KeyCode.A, Modifiers.Control, KeyHookCmd);
keyboardHook.AddHandler(KeyCode.I, Modifiers.Control, KeyHookCmd);
keyboardHook.AddHandler(KeyCode.O, Modifiers.Control, KeyHookCmd);
await keyboardHook.InstallAsync();
I uninstall the keyboard hook as so calling a sub procedure below before closing the user control.
await Task.Run(() => { keyboardHook.RemoveAllHandlers(); keyboardHook.Uninstall(); }).ConfigureAwait(false);
When I hit the finally section of the try/catch block, I am getting an error message when the keyboardHook.Dispose() is fired. That is not captured in the Exception catch block but I see it as I step through the code.
Exception thrown: 'System.Net.Sockets.SocketException' in System.dll ("A blocking operation was interrupted by a call to WSACancelBlockingCall") Exception thrown: 'System.Net.Sockets.SocketException' in System.dll ("A blocking operation was interrupted by a call to WSACancelBlockingCall") Hyperlink: Activate Historical Debugging 17.11s [18376] Worker Thread
I have tried running the keyboardHook.Dispose() and also running this code in another thread.
If you have any input on what I could try or if you need more information from me, please let me know.
Thank you for reviewing this issue.
Are you able to create a minimal reproducible project for that problem? Can you provide a stack trace?
It is not even being thrown in the try/catch block. I even set up a catch block for SocketException prior to the standard Exception catch block and it is not thrown to my NLog routine. I see it in the Visual Studio 2019 diagnostic tools when I am running it locally. I can see if I am able to get a stack trace but I am not sure if I can. When I get some time, I will try to reproduce this on a test application. I don't have the time at the moment.
Closing issue.