GetCharacteristicsAsync function gets stuck in Windows 11 while discovering characteristics of Bluetooth Low Energy devices

ImM@C 1 Reputation point

I have a code snippet that discovers Bluetooth Low Energy device characteristics using GetCharacteristicsAsync function. I am storing the async process returned by this function and waiting for it to be over to obtain the result.

This is working fine in Windows 10 but in Windows 11 the async process gets stuck and never finishes execution. I generally use the Uncached mode but I have tried both Cached and Uncached in Windows 11 and it didn't help.

Is this a known issue in UWP BLE library in Windows 11 and more importantly how do I workaround this? If anybody has useful experience/input relating to this issue it would be much appreciated.

Universal Windows Platform (UWP)
{count} votes

3 answers

Sort by: Most helpful
  1. Andreas Feil 1 Reputation point

    I have the same problem. Sometimes GetCharacteristicsAsync does not return calling something like this:

    CancellationTokenSource cts = new CancellationTokenSource();
    await service.service.GetCharacteristicsAsync(BluetoothCacheMode.Uncached).AsTask<GattCharacteristicsResult>(cts.Token);

    If I pause execution I see that this task is scheduled but not started yet since way over 15 seconds.
    It seems that this is happening if I try to reconnect to a device which had a power cycle so connection was aborted before.

    Is there some news on this?

    0 comments No comments

  2. Patrick Riphagen 1 Reputation point

    In our case it does not get stuck but the status is access denied.

    auto chars = s.GetCharacteristicsAsync(BluetoothCacheMode::Uncached).get();  
    GattCommunicationStatus status = chars.Status();  

    Status gets set to GattCommunicationStatus::AccessDenied

    Same laptop (Dell XPS 15), Windows 10 no problem, only Windows 11

  3. Seres József 1 Reputation point

    This could be related to your situation:

    [Possible solution at the last EDIT]

    But it can be altogether a different thing.
    In my case (using Windows 10, but not an UWP application, calling WinRT libs) this happens:
    Only the first call gives me the attributes, then "Access Denied".
    After some time a single call will give a valid answer again, but it's pretty rare (in one case after 52 seconds, in another 21 seconds).

    In this case I will try to make a solution when everytime I'm asking for data, I will build the BLE from ground up (device detection, looking for correct device, getting attributes), get the data and then destroy everything, then do it again everytime I need data from a device.
    This feels very wrong and could lead to more problems.
    The reasoning behind this that the first time I collect information, everything is accessible.

    Hope this helps someone.

    EDIT1: This is not the case for every Characteristics! For example.: "Battery Level" works every time, but some other characteristics have this behaviour (but only on Windows devices, an Android phone or tablet works everytime, with every characteristic).

    EDIT2: The problem is at a deeper level. Rebuilding the connection from zero each time does not solve the problem. The second time I still can't have the data. But with every program start it works.

    Dispose is the key! After the first request you have to Dispose both the BluetoothLEDevice and the GattDeviceService you get while connecting! The system thinks it is still inuse!

    0 comments No comments