I usually put the connection and receiver code in a background thread, that way if the device is not available or goes away, it doesn't hang the GUI. The background process can update status variables so that the GUI can indicate whether the connection is currently active or not.