1.安装依赖包
Install-Package Hangfier
2.新建OWIN.Startup;(有就不用加了;代码如下)
//获取数据库连接串 string myConn = System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString; Hangfire.GlobalConfiguration.Configuration.UseSqlServerStorage(myConn); app.UseHangfireDashboard(); app.UseHangfireServer();
3.完事后直接运行数据库出现这几张代表成功;然后在url地址栏端口号后面拼上/Hangfire 进入面板
4.类型(官网地址:https://www.hangfire.io/)
//一次性作业用完销毁
var jobId = BackgroundJob.Enqueue(() => "方法名");
//周期作业
RecurringJob.AddOrUpdate(() => "方法名","Cron表达式");
//延期作业多久后执行
var jobId = BackgroundJob.Schedule(() => Console.WriteLine("Delayed!"),TimeSpan.FromDays(7));
//例如----------------------自定义编号----方法名-------------cron表达式-----------------------设置北京时间
RecurringJob.AddOrUpdate("Cold",() => ForecastCold(), dataAdd.GetAutoTime(ForecastType),TimeZoneInfo.Local);
end