停止Quartez.net Scheduler

时间:2012-07-23 12:59:05

标签: asp.net-mvc-3 quartz.net

我有一个Web应用程序,我想实现调度程序我正在使用Quartez.Net库

我在Global.asax

中将以下代码添加到了应用程序中
  protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();

        RegisterGlobalFilters(GlobalFilters.Filters);
        RegisterRoutes(RouteTable.Routes);

        MyScheduler.StartScheduler();
    }

我创建了以下课程以定期开始我的工作

public class MyScheduler
 {
      public void StartScheduler()
       {
        // First we must get a reference to a scheduler
        ISchedulerFactory sf = new StdSchedulerFactory();
        IScheduler sched = sf.GetScheduler();

        // computer a time that is on the next round minute
        DateTimeOffset runTime = DateBuilder.EvenMinuteDate(DateTimeOffset.UtcNow);

        // define the job and tie it to our HelloJob class
        IJobDetail job = JobBuilder.Create<MyJob>()
            .WithIdentity("job1", "group1")
            .Build();

           ITrigger trigger = TriggerBuilder.Create()
                .WithIdentity("trigger1", "group1")
                .WithDailyTimeIntervalSchedule(
                    x => x.StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(14, 41))
                             .EndingDailyAt(TimeOfDay.HourAndMinuteOfDay(14,43))
                             .WithIntervalInSeconds(30))
                .Build();

        // Tell quartz to schedule the job using our trigger
        sched.ScheduleJob(job, trigger);


        // Start up the scheduler (nothing can actually run until the 
        // scheduler has been started)
        sched.Start();           
      }
   }

我想知道如果我让调度程序在不停止运行的情况下运行会有任何问题

1 个答案:

答案 0 :(得分:1)

这是因为你运行调度程序它应该工作的方式。 您必须意识到您的应用程序可能因为不活动而关闭,因此您的调度程序将无法正常工作 Phil Haack wrote about it