开发者

Quartz.net - Trigger not firing when scheduler runs inside a Windows Service

开发者 https://www.devze.com 2023-01-17 08:20 出处:网络
I\'ve got a class library (c#, .net 4.0) implementing a wrapper class for a Quartz.net Scheduler and a bunch of Triggers and Jobs which I\'d like to have executed. This wrapper class has a simple Star

I've got a class library (c#, .net 4.0) implementing a wrapper class for a Quartz.net Scheduler and a bunch of Triggers and Jobs which I'd like to have executed. This wrapper class has a simple Start() and Stop() mathod to start or shutdown the Scheduler.

When I instanciate my wrapper from a console application, it registers my Jobs + Triggers and everything works fine. All jobs are executing as expected and when expected. When I do the same thing from within a Windows Service (which开发者_StackOverflow I have build as a container for the Scheduler) some Triggers never get fired while others do work as expected.

All my Triggers are very simple, like execute every x minutes and repeat forever. I hooked up a global ITriggerListener and logged away everything. The missing Triggers don't fire and they don't misfire. It is as if they are not present.

Unfortunately I didn't manage to set up logging for the Common.Logging infrastructure used by Quartz, so I don't have any information on whats going on inside. Any help is greatly appreciated.


You've mentioned you run Quartz functionality inside a Windows Service. I assume you use something inheriting ScheduleService, hence overriding OnStop() and OnStart(args() as String) methods and I assume you have your Schedule and jobs and triggers registered inside the service OnStart method.

If that's the case, make sure you are preventing the Garbage Collector from "cleaning" your objects.

Gc.KeepAlive(object)

For example, lets imagine we have a System.Timers.Timer inside the OnStart for the windows service. We would have to tell the garbage collector to leave alone the timer, having previously defined de timer at the class level (as an object variable, not as a local function variable)

Private timer As System.Timers.Timer

..and inside the OnStart()

timer As System.Timers.Timertimer = New System.Timers.Timer()
AddHandler timer.Elapsed, AddressOf Tick 'here you define that Tick method will handle it
timer.Enabled = true
timer.Interval = 200000
GC.KeepAlive(timer) 'tell the GC to leave alone the timer

So it could be something similar with your Quartz implementation?

0

精彩评论

暂无评论...
验证码 换一张
取 消