Open mareksm opened 1 month ago
Does this only appear in when using the WinUI 3 library, or can you get the same thing to happen if you use the smart card reader in a Windows API application?
A simple test application using SCardEstablishContext, SCardListReaders, SCardConnect and SCardReleaseContext does not have a similar problem. When the application exits, there is no remaining process running. On the other hand, it is using WinSCard.dll and not Windows.Devices.SmartCards.dll which is pulled in when using WinUI3/WinRT API for smartcards.
What about using the device and smart card WinRT API in a Windows API application?
The same problem - it is calling into Windows.Devices.SmartCards.dll which hangs in WaitForSingleObjectEx during application exit.
Describe the bug
An application uses winrt::Windows::Devices::Enumeration::DeviceWatcher and creates a winrt::Windows::Devices::SmartCards::SmartCardReader instance by calling
co_await winrt::Windows::Devices::Enumeration::DeviceInformation::FindAllAsync(SmartCardReader::GetDeviceSelector())
and then create a reader instance with co_await SmartCardReader::FromIdAsync(device.Id()) from the collection above.
Start the application and connect the smart card reader. Close the application. Open TaskMonitor and observe that application process is still running, Stack trace of that process shows this:
After a while the process ends. If a call to winrt::Windows::Devices::Enumeration::DeviceInformation::FindAllAsync is commented out, the application process ends immediately when the application main window is closed. Application uses deviceWatcher.Stop() call during its cleanup/shutdown routine.
This process exit delay prevents single-app-instance application type from running again when a previous instance has just closed.
Steps to reproduce the bug
Use any of the samples from https://github.com/microsoft/Windows-universal-samples/tree/main/Samples/DeviceEnumerationAndPairing/cppwinrt and add a call to winrt::Windows::Devices::Enumeration::DeviceWatcher and winrt::Windows::Devices::Enumeration::DeviceInformation::FindAllAsync(SmartCardReader::GetDeviceSelector()).
Expected behavior
An app should exit the same way with or without card reader attached.
Screenshots
No response
NuGet package version
None
Packaging type
Packaged (MSIX)
Windows version
Windows 11 version 22H2 (22621, 2022 Update)
IDE
Other
Additional context
No response