使用Quartz.net安排多个计划任务
问题描述:
我试图设置2个和更多的计划任务运行4小时差异,因为当第一个任务凝视。要做到这一点我使用Quartz.NET库像以下:使用Quartz.net安排多个计划任务
ITrigger firstTrigger = TriggerBuilder.Create()
.WithIdentity("Trigger1")
.StartNow()
.WithCronSchedule("0 0 0/4 * * ?")
.ForJob("Job1")
.Build();
IJobDetail secondJob = JobBuilder.Create<StoreAnalyticsUsersUpdate>()
.WithIdentity("Job2")
.Build();
ITrigger secondTrigger = TriggerBuilder.Create()
.WithIdentity("Trigger2")
.StartAt(DateTimeOffset.UtcNow)
.WithCronSchedule("0 0 0/4 * * ?")
.ForJob("Job2")
.Build();
ISchedulerFactory sf = new StdSchedulerFactory();
IScheduler sc = sf.GetScheduler();
sc.ScheduleJob(firstJob, firstTrigger);
sc.ScheduleJob(secondJob, secondTrigger);
sc.Start();
我已经写了测试的目的这个代码,只是为了看看,如果tasks'll正常运行。在我运行我的应用程序后,没有发现任何计划任务...
P.S.我致电的Global.asax类,所以这不是问题的方法...
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RouteConfig.RegisterRoutes(RouteTable.Routes);
JobScheduler.StartCompetitorResearchUpdate(); // this is the method for the above code
}
我在做什么错在这里? 。
答
在
.StartAt(DateTimeOffset.UtcNow).WithCronSchedule("0 0 0/4 * * ?").ForJob("Job2").Build();
测试与
.StartAt(DateTimeOffset.UtcNow).WithCronSchedule("0 0 0/4 * * ?").ForJob(secondJob).Build();
我用一个简单的一个尝试,如:.StartNow()构建();而且两者工作岗位同时正常运行......产生的问题是,现在看来,文我添加了“WithCronSchedule”语句出于某种原因OO –
测试与 ITrigger触发=(ISimpleTrigger)TriggerBuilder.Create() .WithIdentity(” Trigger2“) .StartAt(DateTimeOffset.UtcNow) .WithSimpleSchedule(s => s.WithIntervalInHours(4).RepeatForever()) .ForJob(secondJob) .Build(); –