private void Reconnect() {
this.isForbiddenUntil = DateTime.MinValue;
lock(this.connectionLock) {
if (this.task != null) {
try {
this.cancelTaskSource.Cancel();
this.task.Wait(this.Interval);
this.task.Dispose();
} catch (InvalidOperationException) {
// Disposing the login task before it is finished is not a problem.
} catch (TaskCanceledException) {
// It is also fine if the task is canceled
} catch (AggregateException) {
// It is also fine if the task is canceled
} finally {
this.cancelTaskSource.Dispose();
this.task = null;
}
}
this.Start();
}
}