using Windows.Devices.Bluetooth;
using Windows.Devices.Enumeration;
/* ... */
var deviceWatcher = DeviceInformation.CreateWatcher();
deviceWatcher.Added += async (watcher, deviceInfo) => {
System.Diagnostics.Debug.WriteLine(deviceInfo.Name);
};
deviceWatcher.Start();
使用此功能时,我看不到我的 BLE 设备,但它确实出现在 Windows 10 的“添加蓝牙或其他设备”菜单中。我对观察者的使用可能出了什么问题?
编辑:经过调查,这段代码可以在 .net 4 上运行,但不能在 .net 8 上运行,我不知道为什么。
好吧,至少从 .net 8 开始,API 已经改变,你需要这样才能让它工作: System.Devices.Aep 参考