Search code examples
c#windows-servicesquartz.netquartz.net-2.0

Scheduler doesn't execute job, doesn't appear to even register it


I've created the following:

  • A windows service
  • A quartz scheduler class
  • A single IJob implementation called Worker, which contains a set of tasks that I intend to execute via the Quartz scheduler.

The windows service overrides OnStart to call the scheduling/setup class, which attempts to create a single scheduled task within Quartz that I want to run at a given time frame (At the moment, this is simply once per 30 seconds for example, to test the process)

I've used identical code to one of the samples for creating a job and trigger - the trigger containing a chain of code to start immediately and repeat every 30 seconds, forever.

I then call Schedule() and eventually call Start() on the scheduler object.

I use installutil.exe to shove the Service into the services list, I start the service and see my internal logging framework showing me that the service is starting, the scheduler is being created and the job scheduled (logging output line by line since I've been having issues...) The problem is that the task doesn't run once and doesn't ever repeat. The service sits there running happily, but never spins up to execute anything.

If I use the Exists method, passing in the JobKey - it always says false. The count of Jobs is zero, both tested immediately after scheduling and starting the scheduler.

I am setting up the IJobDetail using this approach:

IJobDetail job = JobBuilder.Create<Worker>()
                .WithIdentity("job1", "group1")
                .Build();

and creating the Trigger with:

TriggerBuilder.Create()
    .WithIdentity("trigger1", "group1")
    .ForJob(job)
    .StartAt(DateTime.Now)
    .WithSimpleSchedule(x => x.WithIntervalInSeconds(30).WithRepeatCount(10))
    .Build();

and then to hook it up:

sched.ScheduleJob(job, trigger);
sched.Start();

I am at a loss as to why this is happening, there is nothing in the event log and nothing wrong with the service and the code appears to run through without any problems as I've shoved logging statements (output to txtfile within /bin/debug) after every line & there's plenty of exception handling.

Any ideas? Is the Build() on the generic Create going to tell the scheduler that the type I've defined is where the Execute() method resides?

Edit Configuration sections I nabbed from this post on SO (@jadenedge's answer) and placed within app.config for the Windows Service. Possibility here of 1.0/2.0 mismatch?

I want the configuration within app.config, ideally, and have no other configuration elsewhere.


Solution

  • Are you starting a thread that keeps the process running? After the service is started, is your process still in memory?