随笔 - 125  文章 - 0  评论 - 20  阅读 - 93350

Asp.Net 之HangFire定时任务配置使用

1.程序集

Install-Package Hangfire.Core
Install-Package Hangfire.SqlServer
Install-Package Hangfire.AspNet

2.web.config加配置

<connectionStrings>
  <add name="sqlserver_connection" connectionString="Data Source=.;Initial Catalog=HangFire;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
<appSettings>

3.项目右击添加项目 Own Startup.cs

复制代码
using Hangfire;
using Microsoft.Owin;
using Owin;
using System;
using System.Threading.Tasks;

[assembly: OwinStartup(typeof(HangFireDemo.Startup))]

namespace HangFireDemo
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            //有关如何配置应用程序的详细信息,请访问 https://go.microsoft.com/fwlink/?LinkID=316888
            //运用SqlServer存储,对应web.config中的connectionStrings中的name
            GlobalConfiguration.Configuration.UseSqlServerStorage("sqlserver_connection"); 

            //注意,当你使用的是MySql作为存储时,需要如下配置
            //运用MySql存储,对应web.config中的connectionStrings中的name
            //GlobalConfiguration.Configuration.UseStorage(new MySqlStorage("mysql_connection"));

            app.UseHangfireDashboard();//配置后台仪表盘
            app.UseHangfireServer();//开始使用Hangfire服务
        }
    }
}
复制代码

4.浏览器访问地址:

http://localhost:4046/hangfire/

 

实现效果:

 sqlserver数据库会生成表结构:

 

5.附Gitee源代码

源代码

 

posted on   RookieBoy666  阅读(44)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示