public void StartLoop(CancellationToken token) { RxLoopConfiguration.Trace($"[{LoopGuid}] Starting loop."); var loopState = new LoopState(token); ScheduleNextRunImmediately(loopState); }
private void DoLoop(LoopState loopState) { RxLoopConfiguration.Trace($"[{LoopGuid}] DoLoop called"); if (loopState.CancellationToken.IsCancellationRequested) { RxLoopConfiguration.Trace($"[{LoopGuid}] Loop cancelled via CancellationToken."); return; } RunActionInternal(loopState.CancellationToken); ScheduleNextRun(loopState); }
private void ScheduleNextRun(LoopState loopState) { RxLoopConfiguration.Trace($"[{LoopGuid}] Scheduling next run."); _schedulerProvider.ThreadPool.Schedule( loopState, DelayBetweenRuns, (scheduler, state) => { DoLoop(state); return(Disposable.Empty); } ); }
private void RunActionInternal(CancellationToken token) { try { RxLoopConfiguration.Trace(DebugOutput()); _action(token); } catch (Exception e) { RxLoopConfiguration.Trace($"[{LoopGuid}] Error running action"); RxLoopConfiguration.ExceptionHandler?.HandleException(e); } }
private void ScheduleNextRunImmediately(LoopState loopState) { RxLoopConfiguration.Trace($"[{LoopGuid}] Scheduling immediate next run."); _schedulerProvider.ThreadPool.Schedule( loopState, TimeSpan.Zero, (scheduler, state) => { DoLoop(state); return(Disposable.Empty); } ); }