If you already know cronExpression, you can call GetNextValidTimeAfter, for example
CronExpression exp = new CronExpression("0 0 0/1 1/1 * ? *"); var nextFire = exp.GetNextValidTimeAfter(DateTime.Now); Console.WriteLine(nextFire);
and if you want more response time, then
for(int i=0 ; i< 9; i++) { if (nextFire.HasValue) { nextFire = exp.GetNextValidTimeAfter(nextFire.Value); Console.WriteLine(nextFire); } }
If you are looking for a more general way to display the next fire time for existing jobs, then check the answer to this question, which works even if you donβt know t using cron expressions. This is for Quartz Version 2
Quartz version 1, the way to get information about the job and the trigger is something like the method below.
public void GetListOfJobs(IScheduler scheduler) { var query = (from groupName in scheduler.JobGroupNames from jobName in scheduler.GetJobNames(groupName) let triggers = scheduler.GetTriggersOfJob(jobName, groupName) select new { groupName, jobName, triggerInfo = (from trigger in triggers select trigger) } ); foreach (var r in query) { if (r.triggerInfo.Count() == 0) { var details = String.Format("No triggers found for : Group {0} Job {1}", r.groupName, r.jobName); Console.WriteLine(details); } foreach (var t in r.triggerInfo) { var details = String.Format("{0,-50} {9} Next Due {1,30:r} Last Run {2,30:r} Group {3,-30}, Trigger {4,-50} {5,-50} Scheduled from {6:r} Until {7,30:r} {8,30:r} ", t.JobName, t.GetNextFireTimeUtc().ToLocalTime(), t.GetPreviousFireTimeUtc().ToLocalTime(), t.JobGroup, t.Name, t.Description, t.StartTimeUtc.ToLocalTime(), t.EndTimeUtc.ToLocalTime(), t.FinalFireTimeUtc.ToLocalTime(), ((t.GetNextFireTimeUtc() > DateTime.UtcNow) ? "Active " : "InActive") ); Console.WriteLine(details); } }
}