1

I've inherited an application that must connect and disconnect from a device via bluetooth. The application more or less works, but as I've added more functionality I've realized that reconnecting to the device after the first connection is problematic. The existing code handles the problems by catching exceptions thrown during the connect, Disposing the BluetoothClient object, reallocating it and retrying. My application UI seems to lock up during the time when these exceptions occur, which obviously is problematic.

I've experimented and tried various things with no luck. I've found that when the problem occurs the BluetoothClient shows that it is connected. So I tried various things to close that existing connection: calling Close(), calling Dispose() and reallocating, etc. None of this seems to make the situation any better. Another thing I've tried, instead of waiting until I want to reconnect, is to try to close the connection at the time when I know the device is offline (I've tried various things like calling Close() or Dispose(), reallocating, etc.). Nothing seems to help.

So my question is, is there a reliable way to close a bluetooth connection such that you can reconnect without throwing exceptions?

I'm using the 32feet.NET/InTheHand.NET library, BTW. Unfortunately, there doesn't seem to be any detailed documentation on the library that I can find.

Is it possible to manage bluetooth connections without using that library? All my googling hasn't found any other options that are well documented.

Mike G
  • 11
  • 1
  • From a simple search, it looks like it's just a simple `.Close()`. May be useful: https://stackoverflow.com/questions/39470036/how-to-control-a-bluetooth-le-connection-on-windows-10 – Jaskier Feb 06 '19 at 17:33
  • I'm not familiar with LE vs. regular bluetooth, but I'm not using the LE related libraries. Can the LE libraries be used with a non-LE device? I have to investigate if my device is LE or not. – Mike G Feb 06 '19 at 17:48
  • My device is not LE so I'm not sure if I can use that framework. – Mike G Feb 06 '19 at 17:58
  • It may be helpful for you to add the work you've attempted to the post. The code you are using, etc. – Jaskier Feb 06 '19 at 18:00
  • Did you try putting the connection is a using block so it gets disposed when it exits block? – jdweng Feb 06 '19 at 18:03
  • I will have to write a test program to recreate the problem easily, then post here. In the mean time, I put my bluetooth scanning/connecting into it's own thread so it no longer interferes with my UI. – Mike G Feb 06 '19 at 19:22

0 Answers0