zoukankan      html  css  js  c++  java
  • TimeJob 定时任务框架

    第一:引入NuGet包:

    QCommon.TimeJob
    

    在StartUp 中注册Job:

      public class Startup
        {
            public void ConfigureServices(IServiceCollection services)
            {
                services.AddTimedJob();
            }
            public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
            {
                if (env.IsDevelopment())
                {
                    app.UseDeveloperExceptionPage();
                }
                app.UseTimedJob();
                app.UseRouting();
    
                app.UseEndpoints(endpoints =>
                {
                    endpoints.MapGet("/", async context =>
                    {
                        await context.Response.WriteAsync("Hello World!");
                    });
                });
            }
        }
    

    编写执行类方法

     public class SendMessageJob:Job
        {
            // Begin 起始时间;Interval执行时间间隔,单位是毫秒,建议使用以下格式,此处为3小时;
            //SkipWhileExecuting是否等待上一个执行完成,true为等待;
            [Invoke(Begin="2021-08-24 15:27",Interval =60*1000, SkipWhileExecuting = true)]
            public void Run()
            {
                Console.WriteLine($"当前时间{DateTime.Now}");
            }
        }
    

      

  • 相关阅读:
    校外实习-7.28
    校外实习-7.27
    校外实习-7.26
    校外实习-7.25
    校外实习-第三周总结
    校外实习-7.22
    校外实习-7.21
    校外实习-7.20
    作业九—总结
    结对编程项目---四则运算(截图总结篇)
  • 原文地址:https://www.cnblogs.com/xiaoyaodijun/p/15180626.html
Copyright © 2011-2022 走看看