Quartz-Timed Task Framework

Use of Quartz

Quartz is another open source project in the field of Job scheduling by the OpenSymphony open source organization. It can be combined with J2EE and J2SE applications or used alone. Quartz can be used to create simple or complex programs that run ten, one hundred, or even tens of thousands of Jobs. Jobs can be made into standard Java components or EJBs. The latest version of Quartz is Quartz 2.3.2.

Not much to say, if you do n’t know how to do it, you can Baidu by yourself.

1. New construction. net fromwork console project ConsoleApp1

2. Use NuGet to add Quartz references

3. Add the following information to the program:

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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            Myqurtz();
            Console.Read();
        }

        public async static void Myqurtz() {
            //创建调度器
            ISchedulerFactory factory = new StdSchedulerFactory();
            var scheduler= awaitfactory.GetScheduler ();
             the await scheduler.Start ();
             // Create Job 
            var Job = JobBuilder.Create <myjob> () WithIdentity (. " the jobs that job1 " , " named group1 " ) .build ();
             // create a trigger, Set trigger time, interval time, repetition frequency 
            var trigger = TriggerBuilder.Create (). WithIdentity ( " trigger1 " , " group1 " ) .StartNow (). WithSimpleSchedule (a => a.WithIntervalInSeconds ( 5 ) .RepeatForever ()) .Build ();
             // Work and triggers are hung on the scheduler 
           await scheduler.ScheduleJob (job, trigger);
        } 

        ///  <summary> 
        /// Content to be processed by the job
         ///  </ summary> 
        public  class Myjob: IJob 
        { 
            public  virtual Task Execute (IJobExecutionContext context) 
            { 
              return   Console.Out.WriteLineAsync ($ " job is working, {DateTime.Now} " ); 
            } 
        } 
    } 
}

 

4. Running effect

 

Guess you like

Origin www.cnblogs.com/1175429393wljblog/p/12702345.html
Recommended