Program.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using Quartz;
  2. using Quartz.Impl;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. namespace ConsoleApplication1
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. ISchedulerFactory sf = new StdSchedulerFactory();
  14. IScheduler sched = sf.GetScheduler(); //创建调度实例
  15. sched.Start(); //开启调度
  16. //aa();
  17. //bb();
  18. Console.WriteLine("启动成功 ");
  19. Console.ReadKey();
  20. }
  21. private static void aa()
  22. {
  23. ISchedulerFactory sf = new StdSchedulerFactory();
  24. IScheduler scheduler = sf.GetScheduler(); //创建调度实例
  25. //创建任务实例
  26. IJobDetail job = JobBuilder.Create<Class1>().WithIdentity(new JobKey("job1")).Build();
  27. //创建触发器实例
  28. ITrigger trigger = TriggerBuilder.Create().StartAt(DateTime.Now.AddSeconds(0)).WithCronSchedule("0/5 * * * * ? ").Build();
  29. scheduler.ScheduleJob(job, trigger); //绑定触发器和任务
  30. scheduler.Start(); //启动监控
  31. }
  32. private static void bb()
  33. {
  34. ISchedulerFactory sf = new StdSchedulerFactory();
  35. IScheduler scheduler = sf.GetScheduler(); //创建调度实例
  36. //创建任务实例
  37. IJobDetail job = JobBuilder.Create<Class2>().WithIdentity(new JobKey("job2")).Build();
  38. //创建触发器实例
  39. ITrigger trigger = TriggerBuilder.Create().StartAt(DateTime.Now.AddSeconds(0)).WithCronSchedule("0/10 * * * * ? ").Build();
  40. scheduler.ScheduleJob(job, trigger); //绑定触发器和任务
  41. }
  42. }
  43. }