为什么characters . readvalueasync()有时会抛出ObjectDisposedException?

2022-01-23 02:44:29 标签 windowsbluetooth-lowenergybluetooth-gatt

当特征调用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();
}
阅读全文

▼ 版权说明

相关文章也很精彩
推荐内容
更多标签
相关热门
全站排行
随便看看

错说 cuoshuo.com —— 程序员的报错记录

部分内容根据CC版权协议转载;网站内容仅供参考,生产环境使用务必查阅官方文档

辽ICP备19011660号-5

×

扫码关注公众号:职场神器
发送: 1
获取永久解锁本站全部文章的验证码