Quartz.NET usage

Have just tried the Quartz.NET 2.x library! See Quartz.NET – Version Migration Guide.

// Construct a scheduler factory.
var collection = new NameValueCollection
    {
        { "quartz.threadPool.threadCount", "3" }
    };
var schedulerFactory = new StdSchedulerFactory(collection);

// Get a scheduler.
var scheduler = schedulerFactory.GetScheduler();
scheduler.Start();

var jobDetail = JobBuilder.Create()
    .Build();

var trigger = TriggerBuilder.Create()
    .StartAt(DateBuilder.FutureDate(10, IntervalUnit.Second))
    .WithSimpleSchedule(x => x.WithIntervalInSeconds(5).RepeatForever())
    .Build();

scheduler.ScheduleJob(jobDetail, trigger);

// To unschedule job use:
//scheduler.UnscheduleJob(trigger.Key);

Leave a Reply (Markdown is enabled)

Your email address will not be published. Required fields are marked *