Core 定时任务之HangFire
ASP.NET Core 使用 Hangfire 很简单,首先,Nuget 安装程序包
> install-package Hangfire -pre
然后ConfigureServices添加配置代码:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.Configure<AppSettings>(Configuration.GetSection("AppSettings"));
//配置好数据库链接后,会在数据库对应的表中生成一些对应的表
services.AddHangfire(x => x.UseSqlServerStorage("Data Source=LocalHost;Initial Catalog= Tab_Hangfire;Integrated Security=true;Persist Security Info=true")); //services.AddTimedJob();
}
然后Configure添加配置代码:
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
} app.UseHangfireServer();
app.UseHangfireDashboard();
//"0 3 * * *"
//RecurringJob.AddOrUpdate(() => Console.WriteLine("Recurring!"), Cron.Minutely());
//这里有几个参数:<要执行的方法所在的类> http://localhost:52815/hangfire/周期性作业的编号名字 类的方法和参数 Corn表达式
RecurringJob.AddOrUpdate<InsertData>("Prozkb",p=>p.insert("zkb"), "0 */1 * * * ?", System.TimeZoneInfo.Local);
//这个Prozkb是RecurringJobId
//app.UseTimedJob();
app.UseMvc(); }
public class InsertData
{
public void insert(string name)
{
string sql = " insert into InsertData values('"+ name + "','',GETDATE())";
ExeNonQuery_B2B(sql);
} public static void ExeNonQuery_B2B(string cmd)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=LocalHost;Initial Catalog= Tab_Hangfire;Integrated Security=true;Persist Security Info=true";
con.Open();
SqlCommand com = new SqlCommand();
com.Connection = con;
com.CommandType = CommandType.Text;
com.CommandText = cmd;
SqlDataReader dr = com.ExecuteReader();
dr.Close();
con.Close();
}
}
http://localhost:52815/hangfire/ 执行到数据库差不多就是一分钟左右


12:38:06.4170000 时间差不多



Core 定时任务之HangFire的更多相关文章
- NET定时任务组件Hangfire
开源的.NET定时任务组件Hangfire解析 项目慢慢就要开工了,很多园友都在问这个事情,看来大伙对这事很上心啊,事情需要一步步的来,尽量写出一个我们都满意的项目.以前每次在博客前面都会扯淡一下,不 ...
- Asp.Ner Core定时任务
AspNet Core定时任务 纪念人类首张黑洞照片发布 第一种方式BackgroundService 基于后台服务类BackgroundService实现,类所在命名空间Microsoft.Exte ...
- 开源的.NET定时任务组件Hangfire解析
项目慢慢就要开工了,很多园友都在问这个事情,看来大伙对这事很上心啊,事情需要一步步的来,尽量写出一个我们都满意的项目.以前每次在博客前面都会扯淡一下,不过很多人都抱怨这样做不好,加上我这人扯淡起来就停 ...
- Core中使用Hangfire
之前使用Quartz.Net,后来发现hangfire对Core的继承更加的好,而且自带管理后台,这就比前者好用太多了. 安装注册 安装 PM> Install-Package Hangfire ...
- .Net Core 定时任务TimeJob
转载自:https://blog.csdn.net/u013711462/article/details/53449799 定时任务 Pomelo.AspNetCore.TimedJob Pomelo ...
- .net core定时任务
1.HangFire HangFire官网 Hangfire项目实践分享 : 讲解的比较详细 2.Quartz.NET https://www.cnblogs.com/best/p/7658573. ...
- ASP.NET Core 中使用 Hangfire 定时启动 Scrapyd 爬虫
用 Scrapy 做好的爬虫使用 Scrapyd 来管理发布启动等工作,每次手动执行也很繁琐;考虑可以使用 Hangfire 集成在 web 工程里. Scrapyd 中启动爬虫的请求如下: curl ...
- Core 定时任务之TimeJob
第一:引入NuGet包: Install-Package Pomelo.AspNetCore.TimedJob -Version -rtm- 第二: 在StartUp 中注册Job: public c ...
- Asp-Net-Core开发笔记:集成Hangfire实现异步任务队列和定时任务
前言 最近把Python写的数据采集平台往.Net Core上迁移,原本的采集任务使用多进程+线程池的方式来加快采集速度,使用Celery作为异步任务队列兼具定时任务功能,这套东西用着还行,但反正就折 ...
随机推荐
- linux常用命令速记
一.命令提示符说明 1. [root@localhost ~]# root: 当前登录用户 localhost: 主机名 ~: 当前所在目录 #: 超级用户提示符($: 普通用户) 2. -rwxr- ...
- Python--day44--navicat使用(知道怎么用就好,要用终端操作,用这个会被人鄙视)
- UVa 10603 Fill [暴力枚举、路径搜索]
10603 Fill There are three jugs with a volume of a, b and c liters. (a, b, and c are positive intege ...
- 【2016常州一中夏令营Day3】
小 W 摆石子[问题描述]小 W 得到了一堆石子,要放在 N 条水平线与 M 条竖直线构成的网格的交点上.因为小 M 最喜欢矩形了,小 W 希望知道用 K 个石子最多能找到多少四边平行于坐标轴的长方形 ...
- ssh批量免密
expect命令在linux下实现批量ssh免密 发布时间:2017-11-27 08:41:39 投稿:laozhang 本次文章主要给大家讲解了在linux系统下用expect命令实现批量ssh免 ...
- Rancher2.x部署K8s
1.安装Docker [root@localhost ~]# docker -v Docker version , build 774a1f4 2.使用Docker运行Rancher : stable ...
- Android应用框架中的四个核心要点
Android应用框架中的四个核心要点:活动(Activity).消息(Intent).视图(View).任务(Task) (一)活动Activity Android系统内部有专门的Activity堆 ...
- 十二、格式化I/O
1.fprintf 表头文件 #include<stdio.h> 定义函数 int fprintf(FILE * stream, const char * format,.......); ...
- Visio数据视觉化处理
形状数据的查看的两种方式 定义形状数据:右键单击数据窗口 打勾的代表可以显示 其他没有打勾的就必须要在开发模式才会显示出来 开发模式就是打开开发工具面板 注意其中类型的设置 类型与格式是一一对应的 不 ...
- eclipse中如何配置jdk
1.在eclipse的上方打开Windows这个选项,选择Preferences==>Java==>Installed JREs 2.然后选择Add==>Standard VM==& ...