Quartz.Extensions.Hosting (opens new window) provides integration with hosted services (opens new window).

TIP

Quartz 3.2 or later required for Quartz.Extensions.Hosting. You can use package Quartz.AspNetCore with version 3.1.

# Installation

You need to add NuGet package reference to your project which uses Quartz.

Quartz 3.1

Install-Package Quartz.AspNetCore 

Quartz 3.2 onwards

Install-Package Quartz.Extensions.Hosting

# Using

You can add Quartz configuration by invoking an extension method AddQuartzHostedService on IServiceCollection. This will add a hosted quartz server into process that will be started and stopped based on applications lifetime.

TIP

See Quartz.Extensions.DependencyInjection documentation to learn more about configuring Quartz scheduler, jobs and triggers.

Example program utilizing hosted services configuration

public class Program
{
    public static void Main(string[] args)
    {
        Log.Logger = new LoggerConfiguration()
            .Enrich.FromLogContext()
            .WriteTo.Console()
            .CreateLogger();
        
        CreateHostBuilder(args).Build().Run();
    }

    public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .UseSerilog()
            .ConfigureServices((hostContext, services) =>
            {
                // see Quartz.Extensions.DependencyInjection documentation about how to configure different configuration aspects
                services.AddQuartz(q =>
                {
                    // your configuration here
                });

                // Quartz.Extensions.Hosting hosting
                services.AddQuartzHostedService(options =>
                {
                    // when shutting down we want jobs to complete gracefully
                    options.WaitForJobsToComplete = true;
                });
            });
}