I wrote a small code to access BLE devices from Win10 and I have registered a callback to look for connection status changes. So, the code that allows me to access device for read/writes looks first for connection status using
if (leDevice.ConnectionStatus() == BluetoothConnectionStatus::Connected)
{
auto servicesResult = co_await leDevice.GetGattServicesAsync();
...
...
}
I see the connectionstatus
doesn't reflect the fact that the device is disconnected until about 10-15 sec and in the meantime, the above code allows access to the device. At such times, the application just exits and there is no crash report (or I don't know where to look for). I am wondering if this is the best way to check if the device is still connected or if I should catch the exception somehow if there is one. Can someone please help if you have any idea?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…