• 关于自动执行,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();
            }
        }
    

    结果:

  • 相关阅读:
    UOS桌面专业版:修改应用图标和应用名称
    unittest使用的时候,print的东西可以在html详情里面显示,但是又想打印在日志中,那就修logging模块中的info方法,使用装饰器
    默认端口
    HTTP HTTPS等协议默认端口
    js特殊字符转义
    vue常用rules校验规则
    HTML中的span标记和div标记
    JS === 与 ==
    Overview of Programming Concepts
    12月9日
  • 原文地址:https://www.cnblogs.com/hepeng/p/6085355.html
Copyright © 2020-2023  润新知