protected override void Restart(bool waitForReadiness = true)
{
lock (this.logger)
{
if (this.isRestarting.WaitOne(0) || this.IsShuttingDown)
{
return;
}
this.ready.Reset();
this.isRestarting.Set();
}
this.logger.Trace(m => m("{0}: Restarting...", this.Endpoint));
this.ResetRestartTask();
var token = this.cancellationTokenSource.Token;
this.restartTask = Task.Factory.StartNew(() => this.StopTask(token), token, TaskCreationOptions.LongRunning, TaskScheduler.Default)
.ContinueWith(_ => this.StartTask(token), token, TaskContinuationOptions.LongRunning, TaskScheduler.Default)
.ContinueWith(
t =>
{
this.isRestarting.Reset();
if (t.IsFaulted)
{
throw t.Exception.InnerException;
}
});
if (waitForReadiness)
{
this.restartTask.Wait(5000);
}
}