Quzrtz.net 示例

//框架.Net Core 2.0
//
先用Nuget 安装最新quartz.net using System; using Quartz; using Quartz.Impl; using System.Threading.Tasks; namespace ConsoleApp { public class Program { static void Main(string[] args){ //创建一个调度器 ISchedulerFactory factory=new StdSchedulerFactory(); IScheduler scheduler =factory.GetScheduler().Result; scheduler.Start(); //创建任务 IJobDetail job = JobBuilder.Create<TimerToDo>() .WithIdentity("job", "group") .Build(); //创建触发器 ITrigger trigger = TriggerBuilder.Create() .WithIdentity("trigger", "group") .WithCronSchedule("0/5 * * * * ?") //5秒执行一次 .Build(); //将任务和触发器添加到调度器中 scheduler.ScheduleJob(job,trigger); Console.ReadLine(); } } public class TimerToDo : IJob { public Task Execute(IJobExecutionContext context) { Console.WriteLine("Hello world."); return Task.CompletedTask; } } }


 

posted @ 2018-06-05 13:10  kerwin cui  阅读(331)  评论(0编辑  收藏  举报