services.AddQuartz(q =>
{
var jobKey = new JobKey("daily job", "job");
q.UseMicrosoftDependencyInjectionJobFactory();
q.AddJob<DailyJob>(jobKey, j => j.WithDescription("Daily Job"));
q.AddTrigger(t => t
.WithIdentity("Cron Trigger")
.ForJob(jobKey)
.StartNow()
//.WithDailyTimeIntervalSchedule(x => x.WithIntervalInSeconds(10).WithRepeatCount(0))
// cron expression
.WithCronSchedule("0 23 14 * * ?")
);
});
// 等待任务执行完成再继续
services.AddQuartzHostedService(options => { options.WaitForJobsToComplete = true; });
services.AddTransient<IJob, DailyJob>();