1

次のように設定したQuartz.NETジョブがあります。

var jobKey = new JobKey("JobName", "JobGroup");
var triggerKey = new TriggerKey("JobName", "JobGroup");
var jobData = new JobDataMap();
jobData.Add("SomeKey", "OriginalValue");
var jobDetail = JobBuilder.Create<JobClass>()
                    .WithIdentity(jobKey)
                    .StoreDurably()
                    .UsingJobData(jobData)
                    .Build();
Scheduler.AddJob(jobDetail, true);
var triggerDetail = TriggerBuilder.Create()
                        .WithIdentity(triggerKey)
                        .StartNow()
                        .WithDailyTimeIntervalSchedule(x => x.OnEveryDay()
                            .StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(04, 07))
                            .EndingDailyAt(TimeOfDay.HourAndMinuteOfDay(06, 07))
                            .WithMisfireHandlingInstructionFireAndProceed())
                        .ForJob(jobKey)
                        .Build();
Scheduler.ScheduleJob(triggerDetail);

次のコードを使用して、そのジョブを手動でトリガーしようとしています。

var jobData = new JobDataMap();
jobData.Add("SomeKey", "SomeValue");
TaskScheduler.Scheduler.TriggerJob(new Quartz.JobKey("JobName", "JobGroup"), jobData);

このコードを手動でトリガーすると、次の値が

context.JobDetail.JobDataMap["SomeKey"] 

"OriginalValue"

それよりも

"SomeValue" 

私が期待するように。私は何が間違っているのですか?

4

2 に答える 2

2

トリガーとジョブの両方にjobDataがあります。

LineTaskScheduler.Scheduler.TriggerJob(new Quartz.JobKey("JobName", "JobGroup"), jobData); はjobDataをトリガーに割り当てます。'SomeValue'はcontext.Trigger.JobDataMap["SomeKey"]で確認できます。

于 2013-02-07T18:29:33.647 に答える
0

参照型の使用は機能します:

//A simple class used here only for storing a string value:
public class SimpleDTO
{
    public string Value { get; set; }
}

void Work() {
    var dto = new SimpleDTO();
    dto.Value = "OriginalValue";
    JobDataMap data = new JobDataMap();
    data["Key"] = dto;

    TaskScheduler.Scheduler.TriggerJob(new Quartz.JobKey("JobName", "JobGroup"), jobData);

    //read modified new value:
    var resultDto = (SimpleDTO)data["Key"];
    Assert.AreEqual("NewValue", resultDto.Value);
}

public void Execute(IJobExecutionContext context)
{
    var simpleDTO = (SimpleDTO)context.MergedJobDataMap["SomeKey"];

    //set a new value:

    simpleDTO.Value = "NewValue";
}
于 2013-07-31T15:56:34.653 に答える