MainService.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System.ServiceProcess;
  2. using Common.Logging;
  3. using Quartz;
  4. using Quartz.Impl;
  5. namespace TransdataService
  6. {
  7. public partial class MainService : ServiceBase
  8. {
  9. #region 私有属性
  10. //日志记录这。
  11. private readonly ILog _logger;
  12. //调度器。
  13. private readonly IScheduler _scheduler;
  14. #endregion
  15. #region 构造方法
  16. /// <summary>
  17. /// 初始化 <see cref="MainService"/> 类的新实例。
  18. /// </summary>
  19. public MainService()
  20. {
  21. InitializeComponent();
  22. this._logger = LogManager.GetLogger("Default");
  23. StdSchedulerFactory factory = new StdSchedulerFactory();
  24. this._scheduler = factory.GetScheduler();
  25. }
  26. #endregion
  27. protected override void OnStart(string[] args)
  28. {
  29. this._scheduler.Start();
  30. this._logger.Info("服务启动");
  31. }
  32. protected override void OnStop()
  33. {
  34. if (!this._scheduler.IsShutdown)
  35. this._scheduler.Shutdown();
  36. this._logger.Info("服务停止");
  37. }
  38. protected override void OnPause()
  39. {
  40. this._scheduler.PauseAll();
  41. base.OnPause();
  42. }
  43. protected override void OnContinue()
  44. {
  45. this._scheduler.ResumeAll();
  46. base.OnContinue();
  47. }
  48. }
  49. }