本文介绍了呼叫调度与ScheduleJobs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图找出如何调用内Quartz.Net的ScheduleJobs方法,而是奋力打造它的预期正确的参数。





下面是我已经试过:

  IJobDetail的JobDetail = JobBuilder.Create<的ReportJob>()
.WithIdentity(theJob)
.Build( );
ITrigger everydayTrigger = TriggerBuilder.Create()
.WithIdentity(everydayTrigger)
//火灾
.WithCronSchedule(0 0 12 1/1 *?)
//立即启动
.StartAt(DateBuilder.DateOf(DateTime.Now.Hour,DateTime.Now.Minute,DateTime.Now.Second,DateTime.Now.Day,DateTime.Now.Month,DateTime.Now .Year))
.Build();
ITrigger yearlyTrigger = TriggerBuilder.Create()
.WithIdentity(yearlyTrigger)
//火灾
.WithCronSchedule(0 0 12 11?*)
//立即开始
.StartAt(DateBuilder.DateOf(DateTime.Now.Hour,DateTime.Now.Minute,DateTime.Now.Second,DateTime.Now.Day,DateTime.Now.Month,DateTime.Now。年))
.Build();
变种词典=新词典< IJobDetail,ISet的< ITrigger>>();
dictionary.Add(的JobDetail,新的HashSet< ITrigger>(){everydayTrigger,yearlyTrigger});
sched.ScheduleJobs((字典,真实); //就是IDictionary的
铸可能在这里

其他的尝试;

  sched.ScheduleJobs(新[] {的JobDetail,新的[] {afternoonTrigger}},真) ; 

&放大器;&安培;

  sched.ScheduleJobs(新[] {新KeyValuePair< IJobDetail,ITrigger>()} ToDictionary< IJobDetail,Quartz.Collection.ISet< ITrigger>(),TRUE); 


解决方案

请确保您使用的收款Quartz的空间,这里是你的代码的一个版本该编译:

  IJobDetail的JobDetail = JobBuilder.Create<的ReportJob>()
.WithIdentity(theJob)
.Build();
ITrigger everydayTrigger = TriggerBuilder.Create()
.WithIdentity(everydayTrigger)
//火灾
.WithCronSchedule(0 0 1 12 / 1 *?)
//立即开始
.StartAt(DateBuilder.DateOf(DateTime.Now.Hour,DateTime.Now.Minute,DateTime.Now.Second,DateTime.Now.Day,日期.Now.Month,DateTime.Now.Year))
.Build();
ITrigger yearlyTrigger = TriggerBuilder.Create()
.WithIdentity(yearlyTrigger)
//火灾
.WithCronSchedule(0 0 12 11?*)
//立即开始
.StartAt(DateBuilder.DateOf(DateTime.Now.Hour,DateTime.Now.Minute,DateTime.Now.Second,DateTime.Now.Day,DateTime.Now.Month,DateTime.Now。年))
.Build();
变种词典=新词典< IJobDetail,Quartz.Collection.ISet< ITrigger>>();
dictionary.Add(的JobDetail,新Quartz.Collection.HashSet< ITrigger>()
{
everydayTrigger,
yearlyTrigger
});
sched.ScheduleJobs(字典,真正的);


I've been trying to figure out how to call the ScheduleJobs methods within Quartz.Net, but struggling to create the correct parameters it's expecting.

Here's what I've tried:

IJobDetail jobDetail = JobBuilder.Create<ReportJob>()
    .WithIdentity("theJob")
    .Build();
ITrigger everydayTrigger = TriggerBuilder.Create()
    .WithIdentity("everydayTrigger")
    // fires
    .WithCronSchedule("0 0 12 1/1 * ?")
    // start immediately
    .StartAt(DateBuilder.DateOf(DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second, DateTime.Now.Day, DateTime.Now.Month, DateTime.Now.Year))
    .Build();
ITrigger yearlyTrigger = TriggerBuilder.Create()
    .WithIdentity("yearlyTrigger")
    // fires
    .WithCronSchedule("0 0 12 1 1 ? *")
    // start immediately
    .StartAt(DateBuilder.DateOf(DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second, DateTime.Now.Day, DateTime.Now.Month, DateTime.Now.Year))
    .Build();
var dictionary = new Dictionary<IJobDetail, ISet<ITrigger>>();
dictionary.Add(jobDetail, new HashSet<ITrigger>() { everydayTrigger, yearlyTrigger });
sched.ScheduleJobs((dictionary, true); // is a cast possible here to IDictionary?

Other attempts;

sched.ScheduleJobs(new [] { jobDetail, new[] { afternoonTrigger } }, true);

&&

sched.ScheduleJobs(new[] { new KeyValuePair<IJobDetail, ITrigger>()}.ToDictionary<IJobDetail, Quartz.Collection.ISet<ITrigger>(), true);
解决方案

Make sure you use the collections from Quartz's namespace, here's a version of your code that compiles:

IJobDetail jobDetail = JobBuilder.Create<ReportJob>()
    .WithIdentity("theJob")
    .Build();
ITrigger everydayTrigger = TriggerBuilder.Create()
    .WithIdentity("everydayTrigger")
    // fires
    .WithCronSchedule("0 0 12 1/1 * ?")
    // start immediately
    .StartAt(DateBuilder.DateOf(DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second, DateTime.Now.Day, DateTime.Now.Month, DateTime.Now.Year))
    .Build();
ITrigger yearlyTrigger = TriggerBuilder.Create()
    .WithIdentity("yearlyTrigger")
    // fires
    .WithCronSchedule("0 0 12 1 1 ? *")
    // start immediately
    .StartAt(DateBuilder.DateOf(DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second, DateTime.Now.Day, DateTime.Now.Month, DateTime.Now.Year))
    .Build();
var dictionary = new Dictionary<IJobDetail, Quartz.Collection.ISet<ITrigger>>();
dictionary.Add(jobDetail, new Quartz.Collection.HashSet<ITrigger>()
                            {
                                everydayTrigger,
                                yearlyTrigger
                            });
sched.ScheduleJobs(dictionary, true);

这篇关于呼叫调度与ScheduleJobs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 23:56