question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AddQuartzHostedService Task Cancellation

See original GitHub issue

When I add Quartz hosted service via

services.AddQuartzHostedService(opt =>
 {
        opt.WaitForJobsToComplete = true;
});

and then shutdown my app how do my jobs know about app shutdown?

Say, I have a job like

public class DummyJob : IJob
    {
        public async Task Execute(IJobExecutionContext context)
        {
            while (!context.CancellationToken.IsCancellationRequested)
            {
                await Task.Delay(TimeSpan.FromSeconds(30), context.CancellationToken);
            }
        }
    }

When the host is shut down I expect context.CancellationToken be cancelled. But it is not. So this job never finishes.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
busyscoutcommented, May 18, 2021

Thanks. It helped:

services.AddQuartz(quartz =>
                    {
                        //...
                        quartz.SetProperty("quartz.scheduler.interruptJobsOnShutdownWithWait", "true");

                    });
0reactions
lahmacommented, Jul 31, 2021

I’ve exposed some new configuration properties both via SchedulerBuilder and DI configuration.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Quartz.net CancellationToken
According to the documentation, you should use Interrupt method to cancel Quartz jobs. ... Apply scheduler.Interrupt after the job executed and ...
Read more >
Using Quartz.NET with ASP.NET Core and worker services
In this post I show how to run Quartz.NET jobs in ASP.NET Core and worker service apps using the Quartz.Extensions.Hosting package.
Read more >
Microsoft DI Integration | Quartz.NET
The scheduling configuration will be checked against database and updated accordingly every time your application starts and schedule is being ...
Read more >
Task Cancellation
In the Task classes, cancellation involves cooperation between the user delegate, which represents a cancelable operation, and the code that ...
Read more >
ASP.NET Core scheduling with Quartz.NET and SignalR ...
This article shows how scheduled tasks can be implemented in ASP.NET Core using Quartz.NET and then displays the job info in an ASP....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found