public void Start(IBootstrappable subject) { var token = _tokenSource.Token; Task.Run(async() => { token.ThrowIfCancellationRequested(); while (!token.IsCancellationRequested) { _logger.LogTrace("The subject is bootstrapped: {isBootstrapped}", subject.IsBootstrapped); if (!subject.IsBootstrapped) { _logger.LogDebug("The subject is not bootstrapped."); try { await subject.BootStrapAsync().ConfigureAwait(false); subject.DeferredExceptions.Clear(); _logger.LogDebug("The subject has successfully bootstrapped."); } catch (Exception e) { _logger.LogDebug("The subject has not successfully bootstrapped.", e); //catch any errors not caught in the bootstrap catch clause subject.DeferredExceptions.Add(e); } } await Task.Delay(SleepDuration, token).ConfigureAwait(false); } }, token); }
public void Start(IBootstrappable subject) { // Ensure that we don't flow the ExecutionContext into the long running task below bool restoreFlow = false; try { if (ExecutionContext.IsFlowSuppressed()) { ExecutionContext.SuppressFlow(); restoreFlow = true; } _ = Execute(subject); } finally { if (restoreFlow) { ExecutionContext.RestoreFlow(); } } }