分享一个优秀的作业调度框架设计源码,非常适合在平时的工作中,定时轮询数据库同步,定时邮件通知,定时处理数据等,它允许开发人员根据时间间隔(或天)来调度作业。
using Quartz;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace JobSchedule
{
public abstract class JobService<T> where T : IJob
{
protected abstract string JobName { get; }
protected abstract string GroupName { get; }
private IJobDetail GetJobDetail()
{
var job = JobBuilder.Create<T>()
.WithIdentity(JobName, GroupName)
.Build();
return job;
}
protected abstract ITrigger GetTrigger();
public void AddJobToSchedule(IScheduler scheduler)
{
scheduler.ScheduleJob(GetJobDetail(), GetTrigger());
}
}
}
它还可以引入Web监控界面:
源码下载:http://letyouknow.net/code/jobschdule.zip