如何在执行时使对象可用于作业实例?

时间:2015-08-08 19:08:27

标签: c# quartz-scheduler quartz.net

以下是在将作业添加到调度程序之前将数据放入x { {s1. a1}. {s2. a2}. ... {sn. an} } 的示例:

JobDataMap

IJobDetail job = JobBuilder.Create<DumbJob>() .UsingJobData("jobSays", "Hello World!") .UsingJobData("myFloatValue", 3.141f) .Build(); 获取值:

JobDataMap

但它只适用于原始类型。因此,我无法在工作执行期间找到转移public class DumbJob : IJob { public void Execute(JobExecutionContext context) { JobDataMap dataMap = context.JobDetail.JobDataMap; string jobSays = dataMap.GetString("jobSays"); float myFloatValue = dataMap.GetFloat("myFloatValue"); } } 的方法。我怎么能这样做?

1 个答案:

答案 0 :(得分:0)

尝试

IJobDetail job = JobBuilder.Create<DumbJob>()
    .UsingJobData("someKey", someObjectOfTypeT)
    .Build();


TypeT someValue = <TypeT>dataMap.Get("someKey");

http://quartznet.sourceforge.net/apidoc/2.0/html/