如何停止或暂停Quartz作业

时间:2017-10-19 10:12:36

标签: quartz.net aspnetboilerplate

我执行了2个工作(MyJob1MyJob2),如下所示:

public async Task<ActionResult> ScheduleJob()
    {
        await _jobManager.ScheduleAsync<MyJob1>(
            job =>
            {
                job.WithIdentity("Job1Identity", "MyGroup")
                    .WithDescription("This is job 1");
            },
            trigger =>
            {
                trigger.StartNow()
                    .WithSimpleSchedule(schedule =>
                    {
                        schedule.RepeatForever()
                            .WithIntervalInSeconds(5)
                            .Build();
                    });
            });

        await _jobManager.ScheduleAsync<MyJob2>(
            job =>
            {
                job.WithIdentity("Job2Identity", "MyGroup")
                    .WithDescription("This is job 2");
            },
            trigger =>
            {
                trigger.StartNow()
                    .WithSimpleSchedule(schedule =>
                    {
                        schedule.RepeatForever()
                            .WithIntervalInSeconds(5)
                            .Build();
                    });
            });

        return Content("OK, scheduled!");
    }

- &GT;我曾尝试使用_jobManager。停止()但它会停止我的所有工作,那么如何仅停止或暂停MyJob2

1 个答案:

答案 0 :(得分:3)

像这样使用Scheduler.PauseJob

var scheduler = StdSchedulerFactory.GetDefaultScheduler();
scheduler.PauseJob(new JobKey("Job2Identity", "MyGroup"));