.NET开发作业调度(job scheduling) - Quartz.NET
Quartz.NET是JAVA Job Scheduling框架Quartz在.NET平台上的实现,可以满足小型乃至大型企业应用中的Job Scheduling。
通过Nuget安装Quartz.NET:
Install-Package Quartz
创建一个简单的Job Scheduling:
using Quartz; using Quartz.Impl; using System; namespace QuartzFirstDemo { public class JobDemo : IJob { public void Execute(IJobExecutionContext context) { Console.WriteLine(DateTime.Now.ToString("r")); } } class Program { static void Main(string[] args) { // 1. Create Scheduler ISchedulerFactory schedulerFactory = new StdSchedulerFactory(); IScheduler scheduler = schedulerFactory.GetScheduler(); // 2. Create Job IJobDetail job = JobBuilder.Create<JobDemo>().Build(); // 3. Create Trigger ISimpleTrigger trigger = (ISimpleTrigger)TriggerBuilder.Create().WithSimpleSchedule(x => x.WithIntervalInSeconds(10) .WithRepeatCount(int.MaxValue)).Build(); // 4. Schedule Job scheduler.ScheduleJob(job, trigger); scheduler.Start(); } } }