【Quartz.NET 3.x Tutorial】Quartz.NET - Lesson 1: Using 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.

Once a scheduler is instantiated(v. 实例化(instantiate的过去分词);具现化,实体化), 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
    NameValueCollection props = new NameValueCollection
    {
        { "quartz.serializer.type", "binary" }
    };
    StdSchedulerFactory factory = new StdSchedulerFactory(props);
    
    // get a scheduler
    IScheduler sched = await factory.GetScheduler();
    await 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();
      
    await 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.

https://www.quartz-scheduler.net/documentation/quartz-3.x/tutorial/using-quartz.html

posted @   FH1004322  阅读(201)  评论(0)    收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示