我升级到 Windows 10 版本 1703 build 15063 (Creators Update) 正式版.当我在 WPF 桌面应用程序中运行以下代码时,BluetoothLEDevice.FromBluetoothAddressAsync 永远不会返回.
I upgraded to Windows 10, version 1703 build 15063 (Creators Update) official release. When I run the following code in a WPF desktop application, BluetoothLEDevice.FromBluetoothAddressAsync never returns.
此代码在我的 Windows 10 更新之前运行良好(即之前的 1607 build 14393).如果在新的 Win 10 1703 中作为 UWP 运行,此代码也可以正常工作.
This code worked on fine before my Windows 10 update (i.e. the previous 1607 build 14393). This code also works fine if it is running as a UWP in the new Win 10 1703.
BluetoothLEAdvertisementWatcher BleWatcher = null;
private void Button_Click(object sender, RoutedEventArgs e)
{
BleWatcher = new BluetoothLEAdvertisementWatcher
{
ScanningMode = BluetoothLEScanningMode.Active
};
BleWatcher.Received += Watcher_Received;
BleWatcher.Start();
}
private async void Watcher_Received(BluetoothLEAdvertisementWatcher sender,
BluetoothLEAdvertisementReceivedEventArgs args)
{
var device = await BluetoothLEDevice.FromBluetoothAddressAsync(args.BluetoothAddress);
// never continues beyond this point above with my BTLE devices that previously worked
}
我按照此处的说明 https://stackoverflow.com/a/37335251/3187714 设置了我的 WPF 桌面应用程序使用 UWP API.
I followed the instructions here https://stackoverflow.com/a/37335251/3187714 to setup my WPF desktop app to use the UWP APIs.
问题更严重,因为当客户开始升级到 Win 10 1703 时,我现有的 WPF 应用程序将被破坏,因为我现有的 exe 不再工作.
The problem is even worse because my existing WPF application will be broken when customers start upgrading to Win 10 1703 because my existing exe no longer works.
是否有其他人在(非 UWP)桌面 exe 中使用 Windows 10 1703 更新遇到此问题?
Is anyone else experiencing this problem with the Windows 10 1703 update in a (Non UWP) desktop exe?
经过进一步的实验,我确实发现如果我在 FromBluetoothAddressAsync 调用中添加了可选的 BluetoothAddressType.Public 2nd 参数,则函数返回,但返回的设备为 null.
After further experiments, I did find if I added the optional BluetoothAddressType.Public 2nd argument to the FromBluetoothAddressAsync call, the function returned, but the device returned was null.
var device = await BluetoothLEDevice.FromBluetoothAddressAsync(args.BluetoothAddress, BluetoothAddressType.Public);
看起来 15063 中围绕蓝牙 API 的安全功能中存在一个错误,导致此问题(我也看到了同样的情况).看看这个帖子:
It looks like there's a bug in the Security functions around the Bluetooth APIs in 15063 that's causing this (I'm seeing the same thing). Check out this thread:
https://social.msdn.microsoft.com/Forums/en-US/58da3fdb-a0e1-4161-8af3-778b6839f4e1/bluetooth-bluetoothledevicefromidasync-does-not-complete-on-10015063?forum=wdk#ef927009-676c-47bb-8201-8a80d2323a7f
tl;dr 对于 C++ 应用程序,它们提供了一个 CoInitializeSecurity 函数来调用.对于其他所有人,他们似乎建议创建一个 AppId在注册表中,因为 P/Invoke 并不好玩.
tl;dr For C++ applications, they provide a CoInitializeSecurity function to call. For everyone else, it looks like they're recommending creating an AppId in the registry, since P/Invoke isn't much fun.
奇怪的是,目前通过 noble-uwp 对我来说一切正常,它使用 C++ 绑定到 UWP 函数以通过 node.js 访问.我只是通过 C# 遇到了问题,并且根据我是在 UWP 还是 WPF/Console/Desktop 应用程序中,事情会在不同的点上失败.
Weirdly enough, things are working fine for me at the moment through noble-uwp, which uses C++ bindings to UWP functions for access via node.js. It's only via C# that I'm having issues, and things fail at different points depending on whether I'm in a UWP or WPF/Console/Desktop application.
按照论坛帖子中的说明将 AppId 添加到注册表后,我又开始工作了.
After adding the AppId to the registry as outlined in the forum post, things worked for me again.
这篇关于FromBluetoothAddressAsync 永远不会在 WPF 应用程序中的 Windows 10 Creators Update 上返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!