Watfaq / SoftU2F-Win

Software U2F authenticator for Windows
The Unlicense
64 stars 20 forks source link

Fix tray icon Exit #74

Closed GoodSign2017 closed 6 months ago

GoodSign2017 commented 6 months ago

The Thread is started in SoftU2FDaemon/Program.cs:

            new Thread(() => { daemon.StartIoLoop(_cancellation.Token); }).Start();

This code in U2FLib/U2FHIDDeviceCommunication.cs blocks the Thread execution:

            var result = DeviceIoControl(
                _device,
                IOCTL_SOFTU2F_FILTER_INIT,
                inputBufferPtr, inputBufferLen,
                outputBufferPtr, outputBufferLen,
                ref nTransferred, IntPtr.Zero);

In SoftU2FDaemon/Program.cs this call initiates the cancellation of Thread:

            if (disposing) _cancellation.Cancel();

However, in C# there are no forced Thread cancellations, the cancellations only work as a signal, and if the Thread is blocked by DeviceIoControl, it won't have its event loop run, therefore it doesn't forcefully end.

I have added Register callback to after the Thread cancellation was signaled, and if an exit was requested too, then we shut down the process.

This fixes #72