码迷,mamicode.com
首页 > 其他好文 > 详细

WorkSample.Quartz

时间:2019-09-01 10:33:26      阅读:84      评论:0      收藏:0      [点我收藏+]

标签:now()   seconds   actor   pack   rgs   lin   syn   oid   async   

using Quartz;
using Quartz.Impl;
using System;
using System.Threading.Tasks;

namespace WorkSample.Quartz
{
    class Program
    {
        static void Main(string[] args)
        {
            ScheduleJobs().GetAwaiter().GetResult();
        }

        private static async Task ScheduleJobs()
        {
            var scheduler = await new StdSchedulerFactory().GetScheduler();

            await scheduler.Start();

            await scheduler.ScheduleJob(
                JobBuilder.Create<FirstJob>().Build(),
                TriggerBuilder.Create().StartNow().WithCronSchedule("0/1 * * * * ? *").Build() // http://cron.qqe2.com/
            );

            await scheduler.ScheduleJob(
                JobBuilder.Create<SecondJob>().Build(),
                TriggerBuilder.Create().StartNow().WithCronSchedule("0/1 * * * * ? *").Build()
            );

            await Task.Delay(TimeSpan.FromSeconds(60));

            await scheduler.Shutdown();
        }
    }

    public class FirstJob : IJob
    {
        public async Task Execute(IJobExecutionContext context)
        {
            await Console.Out.WriteLineAsync("FirstJob Execute");
        }
    }

    public class SecondJob : IJob
    {
        public async Task Execute(IJobExecutionContext context)
        {
            await Console.Out.WriteLineAsync("SecondJob Execute");
        }
    }
}

// Install-Package Quartz

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

 

WorkSample.Quartz

标签:now()   seconds   actor   pack   rgs   lin   syn   oid   async   

原文地址:https://www.cnblogs.com/xiaowangzhi/p/11441412.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!