Program.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using Quartz;
  2. using Quartz.Impl;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Threading.Tasks;
  6. namespace QuartzNETTest
  7. {
  8. class Program
  9. {
  10. public static List<Action> actions = new List<Action>();
  11. static async Task Main(string[] args)
  12. {
  13. //var ret = ConnectionMultiplexer.Connect("127.0.0.1:6379,allowadmin=true");
  14. //IDatabase database = ret.GetDatabase(0);
  15. //ISubscriber subscriber = ret.GetSubscriber();
  16. //subscriber.Subscribe("__keyevent@0__:expired", (channel, notificationType) =>
  17. //{
  18. // Console.WriteLine(channel + "|" + notificationType);
  19. //});
  20. //Console.ReadKey();
  21. StdSchedulerFactory factory = new StdSchedulerFactory();
  22. // get a scheduler
  23. IScheduler scheduler = await factory.GetScheduler();
  24. await scheduler.Start();
  25. // define the job and tie it to our HelloJob class
  26. Guid guid = Guid.NewGuid();
  27. IJobDetail job = JobBuilder.Create<HelloJob>()
  28. .WithIdentity(guid.ToString())
  29. .Build();
  30. guid = Guid.NewGuid();
  31. // Trigger the job to run now, and then every 40 seconds
  32. ITrigger trigger = TriggerBuilder.Create()
  33. .WithIdentity(guid.ToString())
  34. .StartNow()
  35. .WithSimpleSchedule(x => x
  36. .WithIntervalInSeconds(1)
  37. .RepeatForever())
  38. .Build();
  39. await scheduler.ScheduleJob(job, trigger);
  40. rwer: var read = Console.ReadLine();
  41. switch (read)
  42. {
  43. case "1": await scheduler.PauseAll(); break;
  44. case "2": await scheduler.ResumeAll(); break;
  45. }
  46. goto rwer;
  47. }
  48. }
  49. public class HelloJob : IJob
  50. {
  51. public async Task Execute(IJobExecutionContext context)
  52. {
  53. Console.WriteLine(DateTime.Now.ToLongTimeString());
  54. //Program. actions.Add(() => { });
  55. //foreach (var item in Program.actions)
  56. //{
  57. // item();
  58. //}
  59. }
  60. }
  61. }