WorkSample.Quartz

Posted xiaowangzhi

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WorkSample.Quartz相关的知识,希望对你有一定的参考价值。

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的主要内容,如果未能解决你的问题,请参考以下文章