3

i use quartz.net in asp.net mvc for executes some scheduled jobs every 1 minute, normally you can send some parameters to your job in this code i send two string parameter as key/value to my job

IJobDetail SendMatchQuestionJob = JobBuilder.Create<QuestionJob>()

                       .UsingJobData("param1", "value1")
                       .UsingJobData("param2", "value2")
                       .Build();

i want to send an array of strings to scheduled job instead of simple string value,have you any idead? or sample?

thank you in advanced.

Edalat Feizi
  • 1,371
  • 20
  • 32

2 Answers2

4

You could use JobDataMap. The UsingJobData() has an overload for JobDataMap. You could build your JobDataMap something like this:

IJobDetail SendMatchQuestionJob = JobBuilder.Create<QuestionJob>().Build();
SendMatchQuestionJob.JobDataMap["testArray"] = new string[]{"item1", "item2"};

Later you can fetch it from JobDataMap thru execution context:

public void Execute(JobExecutionContext context)
    {
      JobKey key = context.JobDetail.Key;

      JobDataMap dataMap = context.JobDetail.JobDataMap; 
      string[] testArray = (string[]) dataMap["testArray"];
    }
Vinoth
  • 2,419
  • 2
  • 19
  • 34
3

I don't see any valid overloads for UsingJobData() method so maybe a viable option would be passing a string with a delimiter like:

IJobDetail SendMatchQuestionJob = JobBuilder.Create<QuestionJob>()
                       .UsingJobData("params", "value1;value2;value3")
                       .Build();

And just splitting it using string.Split() method afterwards.

kamil-mrzyglod
  • 4,948
  • 1
  • 20
  • 29