主题
Hangfire 使用
提示信息
适合:ASP.NET Core 服务、WinService、控制台常驻程序,要 Cron、重试、持久化、集群
场景:ASP.NET Core 网站后台定时调接口/发邮件/清缓存
1. Hangfire(最省心,Web 项目首选)
NuGet: Hangfire.AspNetCore + Hangfire.SqlServer(或 Redis)
内置 Dashboard(/hangfire)看执行历史/重试/失败,开箱即用
支持 Fire-and-forget / 延迟 / Cron 周期任务 / 任务链
持久化到 SQL Server/Redis,程序重启不丢作业
自带重试、分布式 worker
C#
RecurringJob.AddOrUpdate("ping-site",
() => new HttpClient().GetAsync("https://example.com"),
"0 9 * * *");2.Hangfire 相关资料
GitHub源码:https://github.com/HangfireIO/Hangfire
中文文档:https://www.bookstack.cn/read/Hangfire-zh-official/README.md
GitHub使用示例源码:https://github.com/HangfireIO/Hangfire.Samples (包括控制台应用程序,window服务,ASP.NET MVC,WebForm)


