UWP DeviceWatcher引发已关闭设备的添加事件 [英] UWP DeviceWatcher raises Added event for powered off device

查看:193
本文介绍了UWP DeviceWatcher引发已关闭设备的添加事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个设备观察程序:

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.

如果观察者先前找到了该设备,是否以某种方式对其进行了缓存,这就是导致即使关闭电源也引发了Added事件的原因?有办法防止这种情况吗?

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?

推荐答案

如果观察者先前找到了该设备,是否以某种方式对其进行了缓存,这就是导致即使关闭电源也引发了Added事件的原因?有办法防止这种情况吗?

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?

观察者不会缓存该设备,DeviceWatcher的枚举来自系统级别,并且将花费一些时间来检查Bluetooth设备状态更改.这不是即时响应.

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.

如果要测试DeviceWatcher,请参考以下步骤.

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

  1. 打开系统设置->设备->添加蓝牙或其他设备->蓝牙.

  1. 启动您的DeviceWatcher.您会发现设备信息快速显示在列表视图中.因为列表视图的数据源来自系统级集合.

  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.

停止DeviceWatcher,然后停止蓝牙设备,直到在添加设备"窗口中找不到蓝牙设备信息为止.

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

启动您的DeviceWatcher.您会发现您的蓝牙设备信息不会再显示,并且该应用程序也不会引发您提到的事件

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

注意

对于第三步,如果在蓝牙设备的信息在添加设备"列表中消失之前启动DeviceWatcher,则事件执行顺序将与您提到的一样.

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.

这篇关于UWP DeviceWatcher引发已关闭设备的添加事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆