Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

Connecting and disconnecting Bluetooth device as Serial Port

$
0
0

I am developing a desktop application in C#.

The question is about a Bluetooth device as a serial port.

When I turn on the device and then open my application, I can connect to the correct serial port and read the device just fine.  When I close the application, I make sure that I unsubscribe to the DataReceived event on the serial port, discard output buffers, Close() the serial port and Dispose() the serial port.  Most of the time this works as expected.  If however, I turn off the device (by switch) before closing my application and then try reconnecting after turning it back on, I often get unexplained behavior on my computer.  The mouse (wired USB) and the keyboard will be unresponsive for several seconds, and I get the USB disconnect/connect chime on the speakers.  (In one instance, I had to reboot my system manually.)  I cannot then make a connection without shutting down the device and my application first. 

Are there any objects I can check the status of, before attempting a connection, that will allow me to provide a better user experience in my application?  Is there a way to programmatically shut down the thread that is causing the bad mouse behavior rather than waiting for the system to do it?


Viewing all articles
Browse latest Browse all 8156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>