0

我有一个 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();           
      }
   }

我想知道如果我让调度程序运行而不停止它是否有任何问题

4

1 回答 1

1

这就是它应该工作的方式,因为您正在运行调度程序。您必须意识到您的应用程序可能由于不活动而关闭,因此您的调度程序将无法工作。
Phil Haack 写了关于它的文章。

于 2012-07-23T14:24:19.777 回答