private void ConnectOrReconnect() { try { // Close active connections (if restarting) headTrackingService?.Dispose(); controllerService?.Dispose(); broadcastProxy?.Dispose(); // Give it some time to clean up Thread.Sleep(10); // Connect to the services headTrackingService = new TrackingService(apiClient.CreateProxy <HeadTrackingProxy>()); controllerService = new ControllerService(apiClient.CreateProxy <ControllerProxy>()); broadcastProxy = apiClient.CreateProxy <BroadcastProxy>(); broadcastProxy.HapticPulseReceived += OnHapticFeedbackReceived; headTrackingService.ChangeStatus(IsControllingHeadTracking); } catch (Exception x) { MessageBox.Show(x.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }