Try our conversational search powered by Generative AI!

Unable to stop a scheduled job programmatically

Vote:
 

Hi

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?

Regards

Ritu

#252652
Apr 07, 2021 21:23
Vote:
 

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:
https://www.gulla.net/no/blog/episerver-scheduled-jobs-stop-and-restart/

#252684
Edited, Apr 08, 2021 4:53
Vote:
 

Hi Ritu,

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

#252685
Apr 08, 2021 5:19
Vote:
 

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.

Regards

Ritu

#252737
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.