码迷,mamicode.com
首页 > Web开发 > 详细

Quartz.Net 任务调度之传递参数(2)

时间:2019-12-24 11:32:24      阅读:296      评论:0      收藏:0      [点我收藏+]

标签:传递   sync   OLE   contex   get   div   参数   class   quartz   

1.jobDetail 

  //添加
  //Key:Value
  jobDetail.JobDataMap.Add("张翼德", "张翼德");
  jobDetail.JobDataMap.Add("year",2019);

取值

public class HelloJob : IJob
    {
        public async Task Execute(IJobExecutionContext context)
        {
            await Task.Run(() =>
            {
          //这里
string name = context.JobDetail.JobDataMap.GetString("张翼德"); int year = context.JobDetail.JobDataMap.GetInt("year"); Console.WriteLine($@"JobDetail{name}" + DateTime.Now + ""); Console.WriteLine("JobDetail 当前年份" + year); }); } }

2.Trigger

        //添加
                //Key:Value
                trigger.JobDataMap.Add("刘玄德", "刘玄德");
                trigger.JobDataMap.Add("year", "2020");

取值

public class HelloJob : IJob
    {
        public async Task Execute(IJobExecutionContext context)
        {
            await Task.Run(() =>
            {

          //这里 string name2 = context.Trigger.JobDataMap.GetString("刘玄德");int year2 = context.Trigger.JobDataMap.GetInt("year"); Console.WriteLine($@"Trigger{name2}" + DateTime.Now + ""); Console.WriteLine("Trigger 当前年份" + year2); }); } }

3.MergedJobDataMap

同样的name,取的是后一个的值

  int year3= context.MergedJobDataMap.GetInt("year");

Quartz.Net 任务调度之传递参数(2)

标签:传递   sync   OLE   contex   get   div   参数   class   quartz   

原文地址:https://www.cnblogs.com/mi21/p/12090299.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!