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.