public void Connect() { while (!_isClientConnected) { _dataService = _dataFactories[nextTry].CreateChannel(); try { _dataService.CheckIfAlive(); _isClientConnected = true; Console.WriteLine("Client conneced to server at: {0}", _dataFactories[nextTry].Endpoint.Name); return; } catch (EndpointNotFoundException) { Console.WriteLine("Client could not connect to server at: {0}", _dataFactories[nextTry].Endpoint.Name); nextTry = (nextTry + 1) % 2; _isClientConnected = false; } } }
public bool CheckIfAlive() { bool isAlive = false; bool isSuccess = false; do { try { isAlive = _dataService.CheckIfAlive(); isSuccess = true; } catch { _isClientConnected = false; Connect(); } } while (!isSuccess); return(isAlive); }