Loading

HangFire简单使用

.NET 6简单使用HangFire

// Nuget
install-package Hangfire.AspNetCore
install-package Hangfire.SqlServer

1.appsettings.json添加连接字符串

"ConnectionStrings": {
    "HangfireConnection": "server=.;database=HangfireTest;uid=sa;pwd=1234@qwer"
  }

2.创建数据库

create database 数据库_name
go

3.Program注入服务和中间件

//Program.cs

// Add Hangfire services.
builder.Services.AddHangfire(configuration =>
    configuration.UseSqlServerStorage(
        builder.Configuration.GetConnectionString("HangfireConnection")));
        
// Add the processing server as IHostedService
builder.Services.AddHangfireServer();
// 启用HangFire面板
app.UseHangfireDashboard();

打开http://[ip]:[prot]/hangfire 就可以看到HangFire面板

数据库

posted @ 2022-08-03 01:42  toyz、  阅读(191)  评论(0编辑  收藏  举报