4

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.

walen
  • 7,103
  • 2
  • 37
  • 58
SpaceBison
  • 3,704
  • 1
  • 30
  • 44
  • Are you starting a thread that keeps the process running? After the service is started, is your process still in memory? – Peter Ritchie Jul 25 '12 at 20:23
  • Good question - not explicitly creating a new thread - but I am not used to working with Windows applications or Windows services, so wasn't aware I needed to consider starting one or more of these processes on individual threads. The Win Svc itself is sat in memory once it's started – SpaceBison Jul 26 '12 at 07:23
  • @PeterRitchie - You actually led me to solve my issue - I *did* need a separate thread to keep the process running in the background and once this was in place, it started to come together. If you want to post your comment as a question, I'll accept it! – SpaceBison Jul 27 '12 at 10:29

2 Answers2

3

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

Peter Ritchie
  • 35,463
  • 9
  • 80
  • 98
0

I had this problem and oh boy it drove me absolutely crazy. As it happened I had a spike project that I could always get to run, but my main projects would not run!

The problem: The namespace of my project had dots/periods in it e.g.MyProject.UpdateService where as my spike was simply named QuartzTest.

Debugging through line by line found that when I set my Windows service name to MyProjectUpdateService the Quartz job then registered.

TL/DR: Ensure your Windows service doesn't have dots in the name.

Update: I've done some more testing and it looks like the maximum length of the service name for a Windows service running Quartz is 25 characters. It doesn't error - it just won't start.

Remotec
  • 10,304
  • 25
  • 105
  • 147