zoukankan      html  css  js  c++  java
  • 关于自动执行,Quarz配置太麻烦,试了试FluentScheduler

    Quarz的xml配置和程序集引用我觉得有点多,对于只需要执行一些简单任务的小白简直不能忍,无意间看到了这个FluentScheduler,于是动手试了试。

    话不多说,直接上代码:

    using System;
    using FluentScheduler;
    
    
    namespace HpTest.Fluent
    {
        public class Klass
        {
            public Klass()
            {
                JobManager.Initialize(new MyRegistry());
            }
        }
        public class MyRegistry : Registry
        {
            public MyRegistry()
            {
                // Schedule an ITask to run at an interval
                //Schedule<MyTask>().ToRunNow().AndEvery(2).Seconds();
    
                // Schedule an ITask to run once, delayed by a specific time interval. 
                //Schedule<MyTask>().ToRunOnceIn(5).Seconds();
    
                // Schedule a simple task to run at a specific time
                //Schedule(() => Console.WriteLine("Timed Task - Will run every day at 9:15pm: " + DateTime.Now)).ToRunEvery(1).Days().At(21, 15);
    
                // Schedule a more complex action to run immediately and on an monthly interval
                //Schedule(() =>
                //{
                //    Console.WriteLine("Complex Action Task Starts: " + DateTime.Now);
                //    Console.WriteLine("Complex Action Task Ends: " + DateTime.Now);
                //}).ToRunNow().AndEvery(1).Months().OnTheFirst(DayOfWeek.Monday).At(3, 0);
    
                //Schedule multiple tasks to be run in a single schedule
                Schedule<MyTask>().AndThen<MyOtherTask>().ToRunNow().AndEvery(5).Seconds();
    
               
            }
        }
    
        public class MyTask : IJob
        {
            public static int MyTaskExeCount;
            public void Execute()
            {
                Console.WriteLine("这是MyTask正在第"+ MyTaskExeCount + "次执行");
                MyTaskExeCount += 1;
            }
        }
    
        public class MyOtherTask : IJob
        {
            public void Execute()
            {
                Console.WriteLine("这是MyOtherTask正在执行");
            }
        }
    }

    然后直接在控制台Program中调用:

      class Program
        {
            static void Main(string[] args)
            {
                new Klass();
                Console.ReadKey();
            }
        }
    

    结果:

  • 相关阅读:
    php代码中注释的含义
    MySql-count(*)与count(id)与count(字段)之间的执行结果和性能分析
    mysql通配符进行模糊查询
    我的娃,我的宝贝
    Yii 2.0 query模式语法
    Yii 2.0版本调试输出SQL语句
    mysql高效率随机获取n条数据写法
    mysql语句中判断是否包含某字符串的方法
    应该让老婆多休息
    win10常用快捷键总结
  • 原文地址:https://www.cnblogs.com/hepeng/p/6085355.html
Copyright © 2011-2022 走看看