C# 如何在UWP中断开蓝牙LE连接

C# 如何在UWP中断开蓝牙LE连接,c#,bluetooth,uwp,bluetooth-lowenergy,C#,Bluetooth,Uwp,Bluetooth Lowenergy,我已经写了一个UWP应用程序,为GATT服务做广告。我想知道如何断开连接到我的GATT服务的客户端? 我可以使用DeviceInformation类找到连接的设备,但是调用Session和BluetoothLEDevice对象的Dispose方法没有任何效果 string filter = BluetoothLEDevice.GetDeviceSelectorFromConnectionStatus(BluetoothConnectionStatus.Connected); De

我已经写了一个UWP应用程序,为GATT服务做广告。我想知道如何断开连接到我的GATT服务的客户端? 我可以使用
DeviceInformation
类找到连接的设备,但是调用
Session
BluetoothLEDevice
对象的
Dispose
方法没有任何效果

string filter = BluetoothLEDevice.GetDeviceSelectorFromConnectionStatus(BluetoothConnectionStatus.Connected);
        DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(filter);

        foreach (DeviceInformation d in devices)
        {
            BluetoothLEDevice device = await BluetoothLEDevice.FromIdAsync(d.Id);
            var gattServices = await device.GetGattServicesAsync();
            foreach (var service in gattServices.Services)
            {
                if (service.Session.SessionStatus == GattSessionStatus.Active)
                    service.Session.Dispose();

                service.Dispose();
            }
            device.Dispose();
        }

是否有其他方法可以断开客户端设备的蓝牙连接?

根据章节:另一方面,处理对设备BluetoothLEDevice对象的所有引用(如果系统上没有其他应用程序引用该设备)将在一个小的超时时间后触发自动断开连接。您的代码
service.Dispose()
应该适用于断开连接,但您可能需要一个小的超时等待时间。@SunteenWu MSFT谢谢,连接到设备部分是针对GATT客户端的,当然处置BluetoothLEDevice对象会导致客户端断开连接,但我想断开与服务器端(GATT服务器端)的连接