views:

10

answers:

1

Hi there,

I am working on a Windows service which needs to schedule tasks whenever one of it's web services is called. This could happen hundreds of times per second in a worst case scenario. The task needs to wait a period of time, typically a minute or two, then call a method passing a parameter.

We tried to build our own scheduler class to do this:

public void ScheduleTask<T>(TimeSpan delay, Action<T> task, T arg)
{
    Thread.Sleep(delay);
    threadPool.ExecuteAsync(task, arg);
}

But we figured this wouldn't be appropriate because we could theoretically end up with hundreds of Thread Pool threads all waiting. I am under the impression that there is a finite number of Thread Pool threads available and that this could potentially lock up the system.

I then turned to Quartz.NET and read on their features page that:

Job class instances can be instantiated by Quartz.NET, or by your application's framework.

and on page 3 of their tutorial that the Scheduler creates instances of your Job class (not you) and as such:

it does not make sense to have data-members defined on the job class as their values would be 'cleared' every time the job executes.

Feel free to yell at me, but how do I get a reference to my Job class instance before it executes so I can set a property on it?

  • The property is doing the job of a parameter so i have no interest in it after the Job has executed.
  • I also want to minimise the number of objects it takes to acheive this to keep my code neat and simple.
  • Finally, I seriously dislike using Dictionaries so would prefer to avoid the JobDataMap object.