I have one class that is responsible for all job creation, so I've implemented IJobListener
on it, and registered it to listen for all jobs.
In JobWasExecuted
, I've added the following toward the end of the method:
if (context.JobInstance.GetType().IsSubclassOf(typeof(MyBaseJobType)))
{
(context.JobInstance as MyBaseJobType).Dispose();
}
I have no idea if this is the "correct" way, but it seems to be working. I do not think the scheduler Dispose()
s automatically, because prior to adding the above, my timer seemed to keep going after the job had completed; apparently it was keeping the job thread alive. Also, IJob doesn't implement IDispose
itself, so IMHO expected behavior would not be for the scheduler to Dispose
.
EDIT: Another thought was to Dispose()
of the timer in the timer callback, and also at the end of Execute()
. Thinking this through, though: if the IJob
throws a JobExecutionException
, it won't be properly disposed; so this is probably not a good option.