There are two ways to pass an object that can be retrieved when a Quartz job executes:
Pass the instance in the data map. When you set the job up, add your instance to the map with a key like this:
// Create job etc...
var MyClass _myInstance;
statusJob.JobDataMap.Put("myKey", _myInstance);
// Schedule job...
Retrieve the instance in the job's Execute()
method like this:
public void Execute(IJobExecutionContext context)
{
var dataMap = context.MergedJobDataMap;
var myInstance = (MyClass)dataMap["myKey"];
OR
Add the instance to the scheduler context when you set the job up, like this:
ISchedulerFactory schedFact = new StdSchedulerFactory();
_sched = schedFact.GetScheduler();
_sched.Start();
// Create job etc...
var MyClass _myInstance;
_sched.Context.Put("myKey", myInstance);
// Schedule job...
Retrieve the instance in the job's Execute()
method like this:
public void Execute(IJobExecutionContext context)
{
var schedulerContext = context.Scheduler.Context;
var myInstance = (MyClass)schedulerContext.Get("myKey");
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…