0

is there any way to show a message after finishing a task when we work with quartz.net? in other word how can we found when a task is finished?

I send bulk email using below code and SendMassEmail class

protected void Button1_Click(object sender, EventArgs e)
{
    ConfigureQuartzJobs();
}
public static void ConfigureQuartzJobs()
{



    // construct a scheduler factory
    ISchedulerFactory schedFact = new StdSchedulerFactory();

    // get a scheduler
    IScheduler sched = schedFact.GetScheduler();
    sched.Start();


    IJobDetail job = JobBuilder.Create<SendMassEmail>()
        .WithIdentity("SendJob")
        .Build();
    var trigger = TriggerBuilder.Create()
        .WithIdentity("SendTrigger")
        .WithSimpleSchedule(x => x.WithRepeatCount(0))
        //.StartAt(startTime)
        .StartNow()
        .Build();

    sched.ScheduleJob(job, trigger);
}
user3250818
  • 239
  • 3
  • 16

2 Answers2

1

The job runs on a separate thread to which you won't have a reference. The way to do this would be to have your job notify that it has completed (by writing a record in a database, calling a service, etc) and then have your app display the message.

jvilalta
  • 6,679
  • 1
  • 28
  • 36
1

If I was going to do this..........I would.

Use MEF.

Write an interface for IPostJobRunNotification.

Write 2 concretes. 1 would be a a "DoNothingPostJobRunNotification" concrete. The second would be a "SendEmailPostJobRunNotification"

Wire up my (original) job to call one (or multiple) IPostJobRunNotification(s).

Then you could drop in the concretes as needed.

See this:

What is different between and purpose of MEF and Unity?

You could go Unity injection as well.

Community
  • 1
  • 1
granadaCoder
  • 26,328
  • 10
  • 113
  • 146
  • thanks,I'm beginner in jobs and it's first time I heare aboout MEF so please let me try it. if any seccess I will mark it as answer. – user3250818 Aug 02 '14 at 09:08