Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
336 views
in Technique[技术] by (71.8m points)

windows runtime - WinRT/CPP application exits when the device is accessed after disconnection

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I had to put a try-catch to catch all exceptions for this exe not to crash. But I still do not understand, a) Why in the first place should the delegate ConnectionStatusChanged take so long (10 sec or so) to be invoked ?

Nonetheless, I could catch this exception and return a message to the top layers that there is an issue with connection. Again, I don't if this is the way to do solve this


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...