C# Quartz任务调度器学习

 

下面代码是指给任务的执行方法Execute提供参数,如:

IJobDetail job = JobBuilder.Create<DumbJob>()
    .WithIdentity("myJob", "group1") // name "myJob", group "group1"
    .UsingJobData("jobSays", "Hello World!")
    .UsingJobData("myFloatValue", 3.141f)
    .Build();
View Code

上面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);
    }
} 
View Code

 

posted @ 2017-01-14 23:05  长沙大鹏  阅读(173)  评论(0编辑  收藏  举报