private void LeaderThreadProc(CancellationToken leaderCancellationToken) { Stopwatch iterationStopwatch; do { iterationStopwatch = Stopwatch.StartNew(); try { jobAction(leaderCancellationToken); } catch (OperationCanceledException) { } } while (!leaderCancellationToken.WaitHandle.WaitOne(DateTimeMath.Max(TimeSpan.Zero, delayBetweenIterations - iterationStopwatch.Elapsed))); }
private void TaskExecutionProc() { Stopwatch iterationStopwatch; do { iterationStopwatch = Stopwatch.StartNew(); try { logger.Debug($"Start run task '{task.Id}'"); task.Run(); logger.Debug($"Finish run task '{task.Id}'"); } catch (Exception e) { logger.Error(e, "Error while executing task {TaskId}", new { TaskId = task.Id }); } } while (!stopEvent.Wait(DateTimeMath.Max(TimeSpan.Zero, period - iterationStopwatch.Elapsed))); }