tags:

views:

85

answers:

1

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();

    }
}

PS.bump - really stuck here - any help welcomed

Another way to put forward my issue is: If I want my Job to be able to call back to the Main UI periodically to update progress (e.g. which would be displayed in the progress bar of the MainForm), then how would I arrange to do this? The .NET backgroundworker control has a way to do this, however how would I do this using Quartz.net?