From 5fac89c5afbda9640a1292ef0ece3b7a203b833c Mon Sep 17 00:00:00 2001 From: hex Date: Mon, 30 Jan 2023 13:09:35 +0300 Subject: [PATCH] Update InternalSchedule.cs If you call the scheduler stop method from the job method, then _task will still take the value of the new action, and true will be returned when checking for the Running state. --- FluentScheduler/Scheduler/InternalSchedule.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/FluentScheduler/Scheduler/InternalSchedule.cs b/FluentScheduler/Scheduler/InternalSchedule.cs index 4921f932..0ebd9cc9 100644 --- a/FluentScheduler/Scheduler/InternalSchedule.cs +++ b/FluentScheduler/Scheduler/InternalSchedule.cs @@ -144,6 +144,10 @@ private async Task Run(CancellationToken token) // raising JobEnded event JobEnded?.Invoke(this, new JobEndedEventArgs(exception, startTime, endTime, NextRun)); + // if invoke stop in job + if (token.IsCancellationRequested) + return; + // recursive call // note that the NextRun was already calculated in this run _task = Run(token);