user3250818
user3250818

Reputation: 247

show message after quartz.net job finished

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

Upvotes: 0

Views: 314

Answers (2)

granadaCoder
granadaCoder

Reputation: 27852

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.

Upvotes: 1

jvilalta
jvilalta

Reputation: 6769

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.

Upvotes: 1

Related Questions