为什么characteristic.ReadValueAsync() 有时会抛出ObjectDisposedException?

问题描述

当特征调用 ReadValueAsync 时,以下代码有时会引发 ObjectdisposedException。调试器说该特性有效。违规代码如下所示:

private async void OnAdvertisementReceived(bluetoothleadvertisementwatcher watcher,BluetoothLEAdvertisementReceivedEventArgs eventArgs)
{
slim.Wait();
BluetoothLEDevice bluetoothLEDevice = await BluetoothLEDevice.FromBluetoothAddressAsync(eventArgs.BluetoothAddress);
if (bluetoothLEDevice != null)
{
GattDeviceServicesResult servicesResult = await bluetoothLEDevice.GetGattServicesAsync();
foreach (GattDeviceService service in servicesResult.Services)
{
GattcharacteristicsResult characteristicsResult = await service.GetcharacteristicsAsync();
foreach (GattCharacteristic characteristic in characteristicsResult.characteristics)
{
    if (characteristic.CharacteristicProperties.Equals(GattCharacteristicProperties.Read))
    {
        GattReadResult readResult = await characteristic.ReadValueAsync();
    }
}

}
}
}
slim.Release();
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)