Quartz.NET教程_Lesson 1: Using Quartz

Lesson 1: Using Quartz
課程1:使用Quartz

Before you can use the scheduler, it needs to be instantiated (who’d have guessed?). To do this, you use an implementor of ISchedulerFactory.

在使用調度器之前,它必須被實例化(誰猜到了呢?)。要實現它,你可以使用一個ISchedulerFactory工廠接口的實現。

Once a scheduler is instantiated, it can be started, placed in stand-by mode, and shutdown. Note that once a scheduler is shutdown, it cannot be restarted without being re-instantiated. Triggers do not fire (jobs do not execute) until the scheduler has been started, nor while it is in the paused state.

一旦調度器被實例化,它就能被啓動,掛起和關閉。必須注意一旦調度器被關閉,要啓動它必須要重新實例化。觸發器在調度器沒有啓動之前或者處於暫停狀態時不會執行觸發動作(作業不會被執行)。

Here’s a quick snippet of code, that instantiates and starts a scheduler, and schedules a job for execution:
下面是一個代碼的小范例,範例中實現了調度器的實例化和啓動,以及對一項作業的調度。

Using Quartz.NET

    // construct a scheduler factory
    ISchedulerFactory schedFact = new StdSchedulerFactory();

    // get a scheduler
    IScheduler sched = schedFact.GetScheduler();
    sched.Start();

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

    // Trigger the job to run now, and then every 40 seconds
    ITrigger trigger = TriggerBuilder.Create()
      .WithIdentity("myTrigger", "group1")
      .StartNow()
      .WithSimpleSchedule(x => x
          .WithIntervalInSeconds(40)
          .RepeatForever())
      .Build();

    sched.ScheduleJob(job, trigger);

As you can see, working with Quartz.NET is rather simple. In Lesson 2 we’ll give a quick overview of Jobs and Triggers, so that you can more fully understand this example.

就像你看到的,使用Quart.NET框架十分的簡單,在第二課我們會給出一個作業和觸發器的快速概覽,讓你可以全面的理解這個範例。


希望我的文字能給你帶來幫助:

碼字不易,與君共勉!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章