using Quartz; using Quartz.Impl; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Topshelf; namespace SMP.Tool.TimingTask.Core { public class ServiceRunner : ServiceControl, ServiceSuspend { private readonly IScheduler scheduler; public ServiceRunner() { scheduler = StdSchedulerFactory.GetDefaultScheduler().Result; } public bool Start(HostControl hostControl) { scheduler.Start(); //具体任务启动可在配置文件编写 for (var i = 0; i < JobConfig.jobs.Length; i++) { IJobDetail job1 = JobConfig.jobs[i]; ITrigger trigger1 = TriggerBuilder.Create().StartNow().WithCronSchedule(JobConfig.crons[i]).Build(); scheduler.ScheduleJob(job1, trigger1); } return true; } public bool Continue(HostControl hostControl) { scheduler.ResumeAll(); return true; } public bool Pause(HostControl hostControl) { scheduler.PauseAll(); return true; } public bool Stop(HostControl hostControl) { scheduler.Shutdown(false); return true; } } }