quartz.net - Can I not add a callback delegate method to JobExecutionContext?

Posted by Greg on Stack Overflow See other posts from Stack Overflow or by Greg
Published on 2010-03-26T06:18:50Z Indexed on 2010/03/26 6:23 UTC
Read the original article Hit count: 292

Filed under:

Hi,

BACKGROUND - I have a synchroisation function within my MainForm class. It gets called manually when the user pushes the SYNC button. I want to also call this synchroisation function when the scheduler triggers too, so effectively want SchedulerJob:IJob.Execute() method to be able to call it.

QUESTION - How do I access the MainForm.Sychronization() method from within the SchedulerJob:IJob.Execute() method?

I tried creating a delegate for this method in the MainForm class and getting it added via jobDetail.JobDataMap. However when I try I'm not sure that JobDataMap has a method to pull out a Delegate type???

private void Schedule(MainForm.SyncDelegate _syncNow)
{
    var jobDetail = new JobDetail("MainJob", null, typeof(SchedulerJob));
    jobDetail.JobDataMap["CallbackMethod"] = _syncNow;

    // Trigger Setup
    var trigger = new CronTrigger("MainTrigger");
    string expression = GetCronExpression();
    trigger.CronExpressionString = expression;
    trigger.StartTimeUtc = DateTime.Now.ToUniversalTime();

    // Schedule Job & Trigger 
    _scheduler.ScheduleJob(jobDetail, trigger);
}


public class SchedulerJob : IJob
{
    public SchedulerJob()
    {
    }

    public void Execute(JobExecutionContext context)
    {
        JobDataMap dataMap = context.JobDetail.JobDataMap;
        MainForm.SyncDelegate CallbackFunction = dataMap.getDelegate["CallbackMethod"];  
           **// THIS METHOD DOESN'T EXIST - getDelegate()**
        CallbackFunction();

    }
}

thanks

© Stack Overflow or respective owner

Related posts about quartz.net