简体   繁体   English

使用Quartz.net计划多个计划的任务

[英]Schedule multiple scheduled tasks using Quartz.net

I'm trying to set up 2 and more scheduled tasks to run 4 hours difference since when the first task stared. 自从第一个任务开始执行以来,我正在尝试设置2个和更多的计划任务以运行4个小时。 To do so I'm using Quartz.NET library like following: 为此,我正在使用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();

I've wrote this code for testing purposes, just to see if the tasks'll run properly. 我已出于测试目的编写了此代码,只是为了查看任务是否可以正常运行。 Turns out neither one of the scheduled tasks after I run my application... 运行我的应用程序后,既没有执行预定任务,也没有发现任何一项...

PS I call the method at Global.asax class so that's not the issue... PS我在Global.asax类中调用该方法,所以这不是问题...

protected void Application_Start()
{
    AreaRegistration.RegisterAllAreas();
    RouteConfig.RegisterRoutes(RouteTable.Routes);
    JobScheduler.StartCompetitorResearchUpdate(); // this is the method for the above code
}

What am I doing wrong here? 我在这里做错了什么?

in

.StartAt(DateTimeOffset.UtcNow).WithCronSchedule("0 0 0/4 * * ?").ForJob("Job2").Build();

Test with 测试

.StartAt(DateTimeOffset.UtcNow).WithCronSchedule("0 0 0/4 * * ?").ForJob(secondJob).Build();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM