ECM
ECM
总版主
总版主
  • 社区居民
  • 忠实会员
  • 原创写手
阅读:730回复:0

How to rerun my job after it's end?

楼主#
更多 发布于:2016-05-16 10:53
I'm using the Quartz.Net Library. I wrote some trigger: var t =
   TriggerBuilder.Create()
   .WithIdentity("FirstTask", "TaskGroup")
   .StartAt(DateBuilder.TodayAt(16, 17, 0))
   .EndAt(DateBuilder.TodayAt(17, 17, 0))
   .WithSimpleSchedule(x => x.RepeatForever()
                             .WithIntervalInSeconds(1))
   .Build();
 If I exclude .WithIntervalInSeconds(1) I have an exception that the retry time can't be zero. So, how can I restart my job when it has finished? Also I didn't find the quartz.net configure file to set maximum threads for it.
answer(解决方案):

Much easier than it looked at first: var job = JobBuilder.Create<HelloJob>().WithIdentity(new JobKey("Task_1", "TaskGroup")).Build();
var t = TriggerBuilder.Create()
        .WithIdentity("Trigger_1", "TaskGroup")
        .StartAt(DateBuilder.TodayAt(21, 15, 0))
        .EndAt(DateBuilder.TodayAt(21, 18, 0))
        .Build();
_scheduleService.Scheduler.ScheduleJob(job, t);
 And implementing method in listiner: public void JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException)
{
    if (DateTime.UtcNow > context.Trigger.EndTimeUtc)
        return;
    context.Scheduler.RescheduleJob(context.Trigger.Key, context.Trigger);
}

 

 

 

 

 

 

 

异常中心网是一家专门收集整理程序员编程过程中遇到的常见异常(exception)以及各种异常问答中心的网站。异常中心网旨在,减少程序员在编码遇到异常,处理各种异常时间和痛苦,让程序员能更愉快的、快速的定位异常并查找对应的异常解决方案。异常中心网诚心打造最完美的编程社区为程序员用户服务,努力成为最好的程序员乐园程序员社区程序异常中心程序bug中心异常问答中心

 

喜欢0 评分0
游客

返回顶部