zoukankan      html  css  js  c++  java
  • NETCORE TimeJob定时任务的使用

    引用网址:https://www.cnblogs.com/1285026182YUAN/p/12930687.html

    NETCORE - TimeJob定时任务的使用

    1. 安装 nuget 包

    Install-Package Pomelo.AspNetCore.TimedJob -Pre

    2. startup.cs 

    Start.cs的ConfigureServices注入AddTimedJob服务

    复制代码
            // This method gets called by the runtime. Use this method to add services to the container.
            public void ConfigureServices(IServiceCollection services)
            {
                services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
    
                services.AddTimedJob();
    
            }
    复制代码

    Start.cs的Configure引入UseTimedJob中间件

    复制代码
            // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
            public void Configure(IApplicationBuilder app, IHostingEnvironment env)
            {
                if (env.IsDevelopment())
                {
                    app.UseDeveloperExceptionPage();
                }
                else
                {
                    // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                    app.UseHsts();
                }
    
                app.UseTimedJob();
    
                app.UseHttpsRedirection();
                app.UseMvc();
            }
    复制代码
     

    3. 使用

    新建 JobTest.cs 类 继承Job。

    复制代码
    using Pomelo.AspNetCore.TimedJob;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    
    namespace NETCORE.TimeJob.JobClass
    {
        public class JobTest : Job
        {
    
            //Begin:开始时间   Interval:间隔(毫秒,建议写成1000*60*60 格式)  SkipWhileExecuting:是否等待上一个执行完成
            [Invoke(Begin = "2018-07-27 00:00", Interval = 1000 , SkipWhileExecuting = true)]
            public void TestFun()
            {
                Console.WriteLine("my test job ~!");
            }
    
        }
    }
  • 相关阅读:
    滑动窗口模板
    交换机命令
    针对织梦程序列表字段内可有可无的显示方法
    dedecms中常见问题修改方法
    redis系列之------字典
    1.InfluxDB-官方测试数据导入
    MYSQL第二课
    centos6.8下hadoop3.1.1完全分布式安装指南
    Mysql—添加用户并授权
    什么是全文检索
  • 原文地址:https://www.cnblogs.com/bruce1992/p/15611517.html
Copyright © 2011-2022 走看看