using System; using System.Collections.Generic; using System.Linq; using System.Text; using Quartz; using Quartz.Impl; namespace QuartzDemo1 { public class DumbJob : IJob { public DumbJob() { } public void Execute(JobExecutionContext context) { Console.WriteLine("DumbJob is executing."+DateTime.Now.ToUniversalTime() ); } } class Program { static void Main(string[] args) { // construct a scheduler factory ISchedulerFactory schedFact = new StdSchedulerFactory(); // get a scheduler IScheduler sched = schedFact.GetScheduler(); sched.Start(); // construct job info JobDetail jobDetail = new JobDetail("myJob", null, typeof(DumbJob)); //// fire every hour ////Trigger trigger = TriggerUtils.MakeHourlyTrigger(); //Trigger trigger = TriggerUtils.MakeSecondlyTrigger(); //// start on the next even hour ////trigger.StartTimeUtc = TriggerUtils.GetEvenHourDate(DateTime.UtcNow); //trigger.StartTimeUtc = TriggerUtils.GetEvenMinuteDate(DateTime.UtcNow); //trigger.Name = "myTrigger"; SimpleTrigger trigger = new SimpleTrigger("myTrigger", null, DateTime.UtcNow.AddSeconds(4), null, 2, TimeSpan.FromSeconds(3)); sched.ScheduleJob(jobDetail, trigger); Console.WriteLine("press any key to shut down"); Console.ReadKey(true); Console.WriteLine("shutdown ing..."); sched.Shutdown(); } } }
来源: