WinUI3 C++/winrt packaged SmartCardReader application does not terminate process in a timely manner #4630
Labels
area-External
area-interop
Interoperation support for Windows APIs that need context, like an HWND
area-Lifecycle
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
The text was updated successfully, but these errors were encountered: