MicrosoftDocs / winrt-api

WinRT reference content for developing Microsoft Universal Windows Platform (UWP) apps
Creative Commons Attribution 4.0 International
230 stars 494 forks source link

DeviceWatcher event notes/remarks are confusing #2306

Open russellfoster opened 1 year ago

russellfoster commented 1 year ago

The remarks/notes section for the following are very confusing:

https://github.com/MicrosoftDocs/winrt-api/blob/docs//windows.devices.enumeration/devicewatcher.md https://github.com/MicrosoftDocs/winrt-api/blob/docs//windows.devices.enumeration/devicewatcher_added.md https://github.com/MicrosoftDocs/winrt-api/blob/docs//windows.devices.enumeration/devicewatcher_removed.md https://github.com/MicrosoftDocs/winrt-api/blob/docs//windows.devices.enumeration/devicewatcher_updated.md

[!NOTE] An app must subscribe to all of the added, removed, and updated events to be notified when there are device additions, removals or updates. If an app handles only the added event, it will not receive an update if a device is added to the system after the initial device enumeration completes.

So if I only care about devices that are added or removed, I read this as I need to also listen for updates, otherwise after the enumeration completes I will not get an event for added devices. However, this is not the case in practice, since I get added/removed events after enumeration has completed. Also, the following sample code from MS only uses these events:

https://github.com/microsoft/Windows-universal-samples/blob/main/Samples/CustomHidDeviceAccess/cs/EventHandlerForDevice.cs

Can you confirm that it is not necessary to subscribe to the updated event? And what is the true intended purpose of this note and why does it specifically call out the added event?