private async Task Run() { if (ShouldStop()) { Stop(); } else { try { var result = await Projector.Run(_disposedTokenSource.Token); var anyDispatched = result.Any(x => x.AnyDispatched); if (anyDispatched) { // extend period of work duration _startedAt.Set(DateTime.UtcNow); } _runnerTimer.Interval = _timeoutCalc.CalculateNext(anyDispatched); } catch (Exception e) { Projector.Logger.Fatal("Running projector '{0}' error.\r\n\t{1}", Projector.Name, e.Message); } finally { _runnerTimer.Start(); } } }
private System.Timers.Timer CreateTimer(TimeoutCalculator timeoutCalc) { var timeout = timeoutCalc.CalculateNext(); var result = new System.Timers.Timer(timeout) { AutoReset = false }; result.Elapsed += OnTimerElapsed; return(result); }