# How do i cancel an already runnign recurring job?

**URL:** <https://discuss.hangfire.io/t/how-do-i-cancel-an-already-runnign-recurring-job/7850>\
**Category:** question\
**Tags:** recurring\
**Created:** [October 6, 2020, 11:59pm UTC](https://discuss.hangfire.io/t/how-do-i-cancel-an-already-runnign-recurring-job/7850 "2020-10-06T23:59:48Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![torbjorn](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.hangfire.io/torbjorn/32/1813_2.png) [@torbjorn](https://discuss.hangfire.io/u/torbjorn)\
**Post date:** [October 12, 2020, 4:32pm UTC](https://discuss.hangfire.io/t/how-do-i-cancel-an-already-runnign-recurring-job/7850/3 "2020-10-12T16:32:57Z")

</div>

You can achieve this by using IMonitorinApi and fetch jobs that are processing. Then you can delete them by using IBackgroundJobClient. You need to pass in a cancellationtoken though.

```
    public void InitializeJobs()
    {
        const string myRecurringJobId = "Ftmch-20";
        _recurringJobManager.AddOrUpdate(
            myRecurringJobId,
            Job.FromExpression<MyJob>(j => j.LongRunningJob(null, CancellationToken.None)),
            "0/10 * * * * *");
    }

```

…

```
    public class MyJob
    {
        private readonly IBackgroundJobClient _backgroundJobClient;

        public MyJob(IBackgroundJobClient backgroundJobClient) => _backgroundJobClient = backgroundJobClient;

        public void LongRunningJob(PerformContext context, CancellationToken cancellationToken)
        {
            var currentJobId = context.BackgroundJob.Id;

            var monitoringApi = JobStorage.Current.GetMonitoringApi();

            var jobsToDelete = monitoringApi.ProcessingJobs(0, 1000)
                .Where(j => j.Value.Job.Type == typeof(MyJob))
                .Where(j => j.Key != currentJobId)
                .ToList();

            foreach (var jobToDelete in jobsToDelete)
            {
                _backgroundJobClient.Delete(jobToDelete.Key);
            }

            var endTime = DateTime.UtcNow.AddMinutes(5);
            while (endTime > DateTime.UtcNow)
            {
                cancellationToken.ThrowIfCancellationRequested();
                Thread.Sleep(2000);
            }
        }
    }
```

---

_[View the full topic](https://discuss.hangfire.io/t/how-do-i-cancel-an-already-runnign-recurring-job/7850)._
