Try our conversational search powered by Generative AI!

Unable to stop a scheduled job programmatically



I'm using IScheduledJobRepository to lookup a job and then calling IScheduledJobExecutor.Cancel(id) to stop this job if running, but it's not working. The job keeps running. This logic is not throwing any errors/exceptions either.

Any thoughts on what may be wrong?



Apr 07, 2021 21:23

IScheduledJobExecutor.Cancel() will not immediately kill the scheduled job, but only call job.Stop().

In order for this to work:

- Your job must be stoppable. (IsStoppable returns true)
- Your job must actually stop, if asked to. (Continously checking if .Stop() is called, and then  stop executing)

Code example:

Edited, Apr 08, 2021 4:53

Hi Ritu,

If you are doing some iterations using for/foreach etc.. then make sure you are calling stop method in that loop itself. 

Apr 08, 2021 5:19

Thanks Tomas and Ravindra!

I believe we've missed the stop check in one of the many loops we have in the job logic, which is not letting it stop this way. Will add that.



Apr 08, 2021 16:48
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.