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 に答える