【quartz】 入门

把技术债务给还了,首先来一个最简单的demo;

2.x版比1.x有很多改进,1.x基于fw1、2; 2.x基于fw3.5以上;语法上有很大的不同,摒弃了很多1.x的很多东西;

直接以2.x来demo

 

class Program

    {

        private static void Main(string[] args)

        {

            Start();

        }

        private static void Start()

        {

            IJobDetail jobDetail = JobBuilder.Create<HelloJob>()

                .WithIdentity("testJob_1", "group_1")

                .Build();





            ITrigger trigger = TriggerBuilder

                    .Create()

                    .WithIdentity("trigger_1", "group_1")

                    .StartNow()

                    .WithSchedule(SimpleScheduleBuilder.Create()

                            .WithIntervalInSeconds(10) //时间间隔

                            .WithRepeatCount(5)        //重复次数(将执行6次)

                            )

                    .Build();





            ISchedulerFactory sf = new StdSchedulerFactory();

            IScheduler sched = sf.GetScheduler();

            sched.ScheduleJob(jobDetail, trigger);

            sched.Start();



        }

    }





 public class HelloJob:IJob

    {

        public void Execute(IJobExecutionContext context)

        {

            Console.WriteLine("启动 hellojob!");

        }

    }

效果:

【quartz】 入门

 

见好就收 好处多!

 

你可能感兴趣的:(quartz)