FromBluetoothAddressAsync永远不会在WPF应用程序中的Windows 10 Creators Update上返回 [英] FromBluetoothAddressAsync never returns on Windows 10 Creators Update in WPF Application

查看:144
本文介绍了FromBluetoothAddressAsync永远不会在WPF应用程序中的Windows 10 Creators Update上返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已升级到Windows 10版本1703内部版本15063(创建者更新)正式发布.当我在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版本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第二个参数,该函数返回了,但是返回的设备为空.

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:

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上返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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