调度程序的创建在Global.asax中进行
private void SchedulerStart() { ISchedulerFactory schedulerFactory = new StdSchedulerFactory(); IScheduler scheduler = schedulerFactory.GetScheduler(); scheduler.Start(); IJobDetail job = JobBuilder.Create().WithIdentity("CheckForCompletedJobs").Build(); ITrigger trigger = TriggerBuilder.Create() .WithDailyTimeIntervalSchedule (s => s.WithIntervalInHours(24) .OnEveryDay() .StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(4, 03)) ) .Build(); scheduler.ScheduleJob(job, trigger); }
public class CheckForCompletedJobs : IJob { private readonly IPhotoEventRepository _photoEventRepository; public CheckForCompletedJobs() { _clientRepository = DependencyResolver.Current.GetService(); } public void Execute(IJobExecutionContext context) { //some action with the clientRepository } }