2

I'm looking for an existing job-queue implementation in .Net (3.5) and I was wondering if anyone has suggestions for a good one. I assume that no job queue will be able to do exactly what we want, so I'm looking for one that can easily be extended.

Our basic requirements:

  1. Need to be able to run jobs in parallel or serial. Some jobs might have to be done serially, and some might be able to be run in parallel, even while those serial jobs are being run.
    (I guess technically we could have 2 job queues, but the base implementation still needs to be able to handle both.)
  2. Need to be able to have jobs fire up progress events - but we want to events to be able to fire either when they are ready, or to be queued up and then fired based on a poll from the UI.
    (We want all the events to be processed in the main GUI thread, so on GUI update we are hoping to fire all events that have occurred since the last update.)

Thanks,
Liron

Liron
  • 2,012
  • 19
  • 39

2 Answers2

2

quartz.net is a pretty comprehensive job scheduler

pm100
  • 48,078
  • 23
  • 82
  • 145
0

I've done some similar things, and it's really just basically a message queue, so here are some notes on a basic implementation:

  1. Create a class that contains some queue of your job type (Queue might be a fine choice), a Thread, an AutoResetEvent, a QueueJob method, and an event (say, "HandleJob" or something like that)
  2. Start up the thread. The thread should wait on the event, and then process all jobs in the queue. For each job, just fire the HandleJob event. If you need it on the UI thread, just have your event handler use Invoke or BeginInvoke. Finally, clear the queue.
  3. When QueueJob is called, add the job to the queue and signal the event.
    • Note: you'll want to make sure queue access is synchronized

Also, I think that jobs that should be run in parallel don't really need to be jobs - you can execute them on the ThreadPool.

From here, you can craft in timed execution (say, a job that should run 10 seconds later), execution of iterators, and support for jobs that expose an AsyncWaitHandler (e.g. allow other jobs to execute while it's waiting for something).

Kevin Hsu
  • 1,726
  • 11
  • 14