C# Quartz任务调度器学习
下面代码是指给任务的执行方法Execute提供参数,如:
IJobDetail job = JobBuilder.Create<DumbJob>() .WithIdentity("myJob", "group1") // name "myJob", group "group1" .UsingJobData("jobSays", "Hello World!") .UsingJobData("myFloatValue", 3.141f) .Build();
上面myJob是任务名称,group1是任务组名称,这两个是用来标识任务和分组任务的。
然后下面的jobSay可以理解为是给myJob任务的Execute提供参数的参数名称,Hello Word!是对应的值,下面的
MyFloatValue同理;
下面是DumbJob的代码:
public class DumbJob : IJob { public void Execute(JobExecutionContext context) { JobKey key = context.JobDetail.Key; JobDataMap dataMap = context.JobDetail.JobDataMap; string jobSays = dataMap.GetString("jobSays"); float myFloatValue = dataMap.GetFloat("myFloatValue"); Console.Error.WriteLine("Instance " + key + " of DumbJob says: " + jobSays + ", and val is: " + myFloatValue); } }