C# 为什么GattDeviceService.FromIdASync()无法完成?

C# 为什么GattDeviceService.FromIdASync()无法完成?,c#,bluetooth,bluetooth-lowenergy,windows-10-universal,hm-10,C#,Bluetooth,Bluetooth Lowenergy,Windows 10 Universal,Hm 10,我正在开发一个Windows 10通用应用程序,通过HM-10芯片与嵌入式系统通信 我所做的尝试和其他情况 芯片已经安装好,连接起来没有问题。通过这些设备的iPhone应用程序,我可以通过Arduino串行窗口和iPhone应用程序发送双向消息。 我的计算机也可以看到它,并且可以从Microsoft提供的示例应用程序连接到它 在运行之前,它将在蓝牙设置下配对并连接。我也尝试过不进行配对和连接,但设备信息当时没有发现 MainPage.xaml.cs using System; using Sys

我正在开发一个Windows 10通用应用程序,通过HM-10芯片与嵌入式系统通信

我所做的尝试和其他情况

芯片已经安装好,连接起来没有问题。通过这些设备的iPhone应用程序,我可以通过Arduino串行窗口和iPhone应用程序发送双向消息。 我的计算机也可以看到它,并且可以从Microsoft提供的示例应用程序连接到它

在运行之前,它将在蓝牙设置下配对并连接。我也尝试过不进行配对和连接,但设备信息当时没有发现

MainPage.xaml.cs

using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.Devices.Enumeration;
using Windows.Devices.Bluetooth;
using Windows.Devices.Bluetooth.GenericAttributeProfile;
using System.Threading.Tasks;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409

namespace App1
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    /// 

    public sealed partial class MainPage : Page
    {

        public List<string> deviceList = new List<string>();
        public MainPage()
        {
            this.InitializeComponent();
            Debug.WriteLine("A");
            var taskDevices = getDevices();
            Task.WaitAll(taskDevices);
            Debug.WriteLine("B");

        }
        public async Task<List<string>> getDevices()
        {
            Debug.WriteLine("C");
            foreach (DeviceInformation di in await DeviceInformation.FindAllAsync(GattDeviceService.GetDeviceSelectorFromUuid(GattServiceUuids.GenericAccess), null))
            {
                Debug.WriteLine("D");
                Debug.WriteLine(di.Name);
                Debug.WriteLine(di.Id);
                Debug.WriteLine(di.IsEnabled);
                var bleDevice = await GattDeviceService.FromIdAsync(di.Id);
                Debug.WriteLine("E");
                // Add the dvice name into the list.  
               // deviceList.Add(bleDevice.Name);
            }
            return deviceList;
        }

        private void button_Click(object sender, RoutedEventArgs e)
        {

        }

        private void textBox_TextChanged(object sender, TextChangedEventArgs e)
        {

        }
然后等了一会儿

The thread 0x3c6c has exited with code 0 (0x0).
谢谢您,我非常感谢您的帮助。

您的问题在于:

Task.WaitAll(taskDevices);
。正确的解决方法是使用

在您的特定情况下,您需要(同步地、立即地)在“加载”状态下创建视图——不管您希望它看起来如何。然后,当异步代码完成时,将视图更新为“已加载”状态。有关更多信息,请参阅我的MSDN文章

The thread 0x3c6c has exited with code 0 (0x0).
Task.WaitAll(taskDevices);