1

I'm currently using the 32feet library for bluetooth in my application. I'm trying to check whether the device is still alive before it takes windows the 20s to change the status from "Connected" --> "Paired".

"True" --> "False"

I'm forcing a device refresh with:

holders.storedDevice.Refresh();

but it seems that the refresh isn't actually forcing windows to do anything. For reference storedDevice is of type

BluetoothDeviceInfo name {get; set;}

Timer code:

    private void refreshDevice(object Sender, EventArgs e)
    {
        holders.StoredDevice.Refresh();

        if(!holders.StoredDevice.Connected)
        {
            deviceRefreshTimer.Enabled = false;
            updateTextBox( connectButton ,"Disconnecting...");
            ExecuteSecure(() => connectButton.Enabled = false);
            updateTextBox(statusTextBox, "Lost connection");
            readBackgroundWorker.CancelAsync();
            holders.localClient.Close();
            storedStream = null;
        }

    }
  • One thing to note is that when a `Timer` fires it is not necessarily on the main thread of the application. You may have to marshall back the call to the `.Refresh()` back to this. – Coops Dec 11 '18 at 17:13
  • @Coops Forgot to mention that I'm storing the device globally when I get an initial connection then discard of it when I am done with a connection. But I'll look into the marshall call. Thanks for a recommendation. – proachreasor Dec 11 '18 at 18:56
  • After some digging the `.Refresh()` only affects the displayed friendly name of the device for the system. The description is vague making it seem to have more functionality when called. – proachreasor Dec 11 '18 at 20:02
  • Sounds like you need to dig in to the api documentation and have a “play about” to see what calls do what... – Coops Dec 11 '18 at 20:04
  • It's a little bit hard to unertand what do you wantr to do. Do you really want to knwo if device is available? If so there is other way (faster) to do it. For examp,e you can simple r\disacover device and see anly available devices (out Bluetooth Framework can do it. Also you can "ping" each device to check is it really in range. Or you cam try to connect to device to check if it is available. Lot of ways. – Mike Petrichenko Dec 11 '18 at 20:49

0 Answers0