void Reconnect() { _stream.Dispose(); _stream = null; int attempts = 0; while (attempts < ReconnectAttempts || ReconnectAttempts == -1) { Debug.WriteLine(String.Format("Reconnect attempt #{0}/{1}", attempts + 1, ReconnectAttempts)); if (InitIO(_connector.Reconnect(ReconnectTimeout))) { return; } Thread.Sleep(TimeSpan.FromMilliseconds(ReconnectTimeout)); attempts++; } if (!Connected) { throw new IOException("Could not reconnect after " + attempts + " attempts"); } }