private void ResetRestartTask()
{
if (!this.restartTask.IsCompleted)
{
this.cancellationTokenSource.Cancel();
try
{
this.restartTask.Wait();
}
catch (AggregateException ex)
{
ex.Handle(
e =>
{
this.logger.ErrorFormat("{0}: Caught unexpected exception.", e, this.Endpoint);
return true;
});
}
catch (Exception ex)
{
this.logger.ErrorFormat("{0}: Caught unexpected exception.", ex, this.Endpoint);
}
finally
{
this.cancellationTokenSource = new CancellationTokenSource();
}
}
}