Allow connecting thread to finish before exiting main window