# How to send cancellation token to terminate recurring jobs that are running every second

**URL:** <https://discuss.hangfire.io/t/how-to-send-cancellation-token-to-terminate-recurring-jobs-that-are-running-every-second/2767>\
**Category:** question\
**Created:** [December 21, 2016, 3:38am UTC](https://discuss.hangfire.io/t/how-to-send-cancellation-token-to-terminate-recurring-jobs-that-are-running-every-second/2767 "2016-12-21T03:38:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nnadig](https://avatars.discourse-cdn.com/v4/letter/n/76d3ee/32.png) [@nnadig](https://discuss.hangfire.io/u/nnadig)\
**Post date:** [December 21, 2016, 3:38am UTC](https://discuss.hangfire.io/t/how-to-send-cancellation-token-to-terminate-recurring-jobs-that-are-running-every-second/2767/1 "2016-12-21T03:38:54Z")

</div>

Hi,

I am launching a background recurring job using the following API  
RecurringJob.AddOrUpdate( () =\> Cancelable( JobCancellationToken.Null), Cron.Minutely);

My goal is to stop all the processing and recurring jobs when the service is terminated. This  
can be also done by selecting the “Delete” button in the dashboard.

For some reason, when I delete the task through dash board, the cancellationtoken is not  
set to true . How do I capture the jobID or the processing or the recurring job?

I have used var recurring = connection.GetRecurringJobs().FirstOrDefault(p =\> p.Id == “HangFireService.Cancelable”);

How do we terminate processing jobs . Please let me know.

Thanks,

---

<div class="post-metadata">

**Author:** ![pieceofsummer](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.hangfire.io/pieceofsummer/32/785_2.png) [@pieceofsummer](https://discuss.hangfire.io/u/pieceofsummer)\
**Post date:** [December 21, 2016, 3:47am UTC](https://discuss.hangfire.io/t/how-to-send-cancellation-token-to-terminate-recurring-jobs-that-are-running-every-second/2767/2 "2016-12-21T03:47:38Z")

</div>

Call IJobCancellationToken.ThrowIfCancellationRequested() periodically in your job.

---

<div class="post-metadata">

**Author:** ![nnadig](https://avatars.discourse-cdn.com/v4/letter/n/76d3ee/32.png) [@nnadig](https://discuss.hangfire.io/u/nnadig)\
**Post date:** [December 21, 2016, 4:07am UTC](https://discuss.hangfire.io/t/how-to-send-cancellation-token-to-terminate-recurring-jobs-that-are-running-every-second/2767/3 "2016-12-21T04:07:14Z")

</div>

It does not work as the token is set to false all the time… Can you provide me more details

RecurringJob.AddOrUpdate( () =\> Cancelable( JobCancellationToken.Null), Cron.Minutely);

How do I trigger the deletion of the jobs without the dashboard… Like I want kill all the jobs when I kill the service  
in the console application.

Thanks

---

<div class="post-metadata">

**Author:** ![nnadig](https://avatars.discourse-cdn.com/v4/letter/n/76d3ee/32.png) [@nnadig](https://discuss.hangfire.io/u/nnadig)\
**Post date:** [December 21, 2016, 4:14am UTC](https://discuss.hangfire.io/t/how-to-send-cancellation-token-to-terminate-recurring-jobs-that-are-running-every-second/2767/4 "2016-12-21T04:14:06Z")

</div>

When I exit the service, is it sufficient that I just kill the recurring job and not the ones that are processing as I do not want any tasks hanging in the background . thanks
