private void BlockingConnect() { while (!token.IsCancellationRequested) { try { log.Debug("Trying to connect to broker"); connection = connectionFactory.CreateConnection(); log.Debug("Connection created"); connection.ConnectionShutdown += HandleConnectionShutdown; aggregator.Notify(new ConnectionEstablished(this)); return; } catch (BrokerUnreachableException e) // looking at the client source it appears safe to catch this exception only { log.Error("Cannot create connection, broker is unreachable", e); aggregator.Notify(new ConnectionAttemptFailed()); if (waiter.Wait(token.WaitHandle, ConnectionAttemptInterval)) { return; } } } }