Edalat Feizi Edalat Feizi - 2 months ago 18
ASP.NET (C#) Question

How to schedule a job to run 10 sec later in quartz.net?

I have a scheduled job that will fire every 1 minute, how can I schedule a job to run 10 sec later when added to scheduler?

var jobKey = new JobKey("firstJob", "jobGroup");

var firstJob = JobBuilder.Create<MatchJob>()

var firstTrigger = TriggerBuilder.Create()
.WithSimpleSchedule(x => x.WithIntervalInMinutes(1).RepeatForever())

AddJobToScheduler(firstJob, firstTrigger);


What about doing it with a cron-expression looking something like this: 10 0/1 * * * ? *? This would fire with one minute intervals but 10 seconds after your other job.

To add a cron-expression simply use .WithCronSchedule("10 0/1 * * * ? *") on your trigger.

The cron expression for your current job would be 0 0/1 * * * ? *. For a good tutorial on cron-expressions check this out!


If what you want is a job that is fired 10 seconds after its added to scheduler you could just do .StartAt(DateTime.Now.AddSeconds(10))