public void AttainState(AMQState s) { if (_currentState != s) { StateWaiter sw = null; try { _logger.Debug("Adding state wait to reach state " + s); sw = new StateWaiter(s); AddStateListener(sw); sw.WaituntilStateHasChanged(); // at this point the state will have changed. } finally { RemoveStateListener(sw); } } }