2

ok, this is a newbie question, i searched through the net couldn't found any clue, here is my problem:

from the example usualy trigger and job scheduled by using IScheduler.ScheduleJob(job, trigger) now i used JobFactory i tried to use IScheduler.ScheduleJob(trigger) but ends with Trigger's related Job's name cannot be null exception

here is my simplyfied code:

Job

class DummyJob : IJob
{
    public void Execute(IJobExecutionContext context)
    {
        Console.WriteLine("executed");
    }
}

Job Factory

class JobFactory : IJobFactory
{
    public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler)
    {
        return new DummyJob();
    }
}

Main Program

class Program
{
    static void Main(string[] args)
    {
        ISchedulerFactory sf = new StdSchedulerFactory();
        IScheduler sc = sf.GetScheduler();

        ITrigger trigger = TriggerBuilder.Create()
            .ForJob()
            .StartAt(DateTime.Now.AddSeconds(5))
            .Build();

        sc.JobFactory = new JobFactory();
        sc.ScheduleJob(trigger);
        sc.Start();

        Console.WriteLine("waiting...");
        Console.ReadLine();
        sc.Shutdown();
    }
}

any idea?

Jehof
  • 34,674
  • 10
  • 123
  • 155
bonjorno
  • 201
  • 2
  • 12

1 Answers1

3

As far as scheduling is concerning, I don't think you should be doing anything different just because you are using your own JobFactory.

Your main program is invalid because it doesn't know what job you want to schedule.

Your example is probably over simplified and doesn't give a clear idea or what you are trying to achieve with your JobFactory, but perhaps its worth pointing out that the purpose of a JobFactory is not to specify which job to run, but to specify how a particular job is supposed to start and hence is expecting bundle.JobDetail to contain the information about which job to run.

sgmoore
  • 15,694
  • 5
  • 43
  • 67