我是quartz.net 的新手。我想构建一个简单的基于窗口的应用程序来安排任务。假设我有 4 个任务,它的开始和结束时间示例
Breakfast ; 8:00;8:30
Lunch;13:00;13:30
dinner;19:30;20:00
现在我想当我在上午 8:00 单击按钮时,应该会出现一个消息框,其中包含“早餐开始!!!”的文本 上午 8:30 再次出现一个消息框,其中包含“早餐结束!!!”的文本 等等。
我已经完成了教程。但混淆如何进行。谁能帮我吗?
编辑
是否可以为此使用一项工作和一个触发器?
IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler();
for (int i = 0; i < listBox1.Items.Count; i++)
{
string[] strArr = Regex.Split(listBox1.Items[i].ToString(), @";", RegexOptions.Multiline);
// define the job and tie it to our HelloJob class
IJobDetail jobStart = JobBuilder.Create<HelloJob>()
.WithIdentity("job" + i, "group1") // name "myJob", group "group1"
.StoreDurably()
.UsingJobData("jobSays", strArr[0].ToUpper().Trim() + " " + "starts")
.Build();
string[] ArrStart = strArr[1].Trim().Split(':');
ITrigger triggerstart = TriggerBuilder.Create()
.WithIdentity("trigger" + i, "group1")
.WithSchedule(CronScheduleBuilder.DailyAtHourAndMinute(Convert.ToInt32(ArrStart[0]), Convert.ToInt32(ArrStart[1])))
// .WithSimpleSchedule(x => x.WithMisfireHandlingInstructionIgnoreMisfires()
.ForJob(jobStart)
.Build();
// .WithSchedule(CronScheduleBuilder.CronSchedule("0 4 06 1/1 * ? *"))
// Tell quartz to schedule the job using our trigger
scheduler.ScheduleJob(jobStart, triggerstart);
scheduler.Start();
string[] Arrend = strArr[2].Trim().Split(':');
IJobDetail jobend = JobBuilder.Create<HelloJob>()
.WithIdentity("job1" + i, "group1")
.StoreDurably()
.UsingJobData("jobSays", strArr[0].ToUpper().Trim() + " " + "end")
.Build();
ITrigger triggerend = TriggerBuilder.Create()
.WithIdentity("trigger1" + i, "group1")
.WithSchedule(CronScheduleBuilder.DailyAtHourAndMinute(Convert.ToInt32(Arrend[0]), Convert.ToInt32(Arrend[1])))
// .WithSimpleSchedule(x => x.WithMisfireHandlingInstructionIgnoreMisfires()
.ForJob(jobend)
.Build();
scheduler.ScheduleJob(jobend, triggerend);
scheduler.Start();
}
}
catch (SchedulerException se)
{
Console.WriteLine("Scheduler Exception : " + se);
}
}
public class HelloJob : IJob
{
public void Execute(IJobExecutionContext context)
{
JobKey key = context.JobDetail.Key;
JobDataMap dataMap = context.JobDetail.JobDataMap;
string jobSays = dataMap.GetString("jobSays");
MessageBox.Show(jobSays);
}
}