views:

558

answers:

3

Hi, I need to schedule a trigger to fire every minute, next minute if the job is still running the trigger should not fire and should wait another minute to check, if job has finished the trigger should fire Thanks

+1  A: 

If you're using Quartz.NET, you can do something like this in your Execute method:

object execution_lock = new object();

public void Execute(JobExecutionContext context) {
    if (!Monitor.TryEnter(execution_lock, 1)) {
        return,
    }

    // do work

    Monitor.Exit(execution_lock);
}

I pull this off the top of my head, maybe some names are wrong, but that's the idea: lock on some object while you're executing, and if upon execution the lock is on, then a previous job is still running and you simply return;

EDIT: the Monitor class is in the System.Threading namespace

DonkeyMaster
+3  A: 

I didnt find any thing about monitor.enter or something like that, thanks any way the other answer is that the job should implement the 'StatefulJob' interface. As a StatefulJob, another instance will not run as long as one is already running thanks again

ilpostino
A: 

IStatefulJob is the key here. Creating own locking mechanisms may cause problems with the scheduler as you are then taking part in the threading.

Marko Lahma