0

I have an ASP.NET Core MVC project that uses Quartz.NET to run background jobs.

Problem: I have configured the IIS application pool for this app with:

StartMode = AlwaysRunning
Idle Timeout = 0 (disabled)
Preload Enabled = true (Application level)

Despite this configuration, when the application pool recycles, the Quartz jobs are not scheduled. The jobs only start after the application receives an HTTP request to any controller.

I want the Quartz scheduler to start immediately after the application pool recycles, without waiting for an HTTP request.

New contributor
saad sb is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
1

1 Answer 1

-1
using Quartz;

var builder = WebApplication.CreateBuilder(args);
// Add Quartz services
builder.Services.AddQuartz(q =>
{
// Register your job and trigger
    var jobKey = new JobKey("SampleJob");
    q.AddJob<SampleJob>(opts => opts.WithIdentity(jobKey));
    q.AddTrigger(opts => opts
        .ForJob(jobKey)
        .WithIdentity("SampleJob-trigger")
        .WithSimpleSchedule(x => x.WithIntervalInSeconds(60).RepeatForever()));
});
// Ensure Quartz starts with the app
builder.Services.AddQuartzServer(options =>
{
    options.WaitForJobsToComplete = true;
});
builder.Services.AddControllersWithViews();

var app = builder.Build();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();

app.MapDefaultControllerRoute();
app.Run();
New contributor
Jessyジェシー is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
Sign up to request clarification or add additional context in comments.

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.