UWP DeviceWatcher raises Added event for powered off device

帅比萌擦擦* 提交于 2019-12-23 23:30:33

问题


I created a device watcher:

DeviceInformation.CreateWatcher(BluetoothLEDevice.GetDeviceSelectorFromDeviceName("..."));

If the bluetooth device I'm looking for is powered off, an Added event is raised immediately followed by a Removed event. If it's powered on, I only get an Added event.

Is the device somehow being cached if it was previously found by the watcher, and that's what causes the Added event to be raised despite being powered off? Is there a way to prevent this?


回答1:


Is the device somehow being cached if it was previously found by the watcher, and that's what causes the Added event to be raised despite being powered off? Is there a way to prevent this?

The device would not be cached by the watcher, the enumeration of DeviceWatcher comes from system level, and it will take a little time to check the Bluetooth device status change. It is not instant response.

If you want test DeviceWatcher please refer to the following steps.

  1. Open system Settings --> Devices-->Add Bluetooth or other device-->Bluetooth.

  1. Start your DeviceWatcher. You will find that the device info display in the list view quickly. Because the data source of list view comes from system level collection.

  2. Stop your DeviceWatcher and then stop your bluetooth device until you could not find your bluetooth device info in "Add a device" window.

  3. Start your DeviceWatcher. You will find the your bluetooth device info would not display again and the application would not raise event as your mentioned

Note

For third step, if you start DeviceWatcher before the information of bluetooth device disappearing in the "Add a Device" list, then the events execution order will be just like what you mentioned.



来源:https://stackoverflow.com/questions/43956362/uwp-devicewatcher-raises-added-event-for-powered-off-device

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!