我使用C# ASP.NET Core3.1和Hangfire来安排后台作业。默认情况下,如果后台作业执行过程中出现异常,则有10次重试尝试。我知道可以使用AutomaticRetry属性将其设置为0,但我不希望在每个后台作业上都这样做。相反,我希望默认值为0,并且只使用属性手动指定它,在非常罕见的情况下,我希望它不是0。谢谢。
发布于 2021-03-04 09:05:49
我曾在.Net经典版中这样做过,我想在.Net内核中也不应该有什么不同
// disable automatic retry if a job fails
Hangfire.GlobalJobFilters.Filters.Add(new AutomaticRetryAttribute() { Attempts = 0 }); 发布于 2022-03-03 16:08:12
关于ASP.NET核心+(5,6)你可以这样做:
services.AddHangfire((serviceProvider, globalConfiguration) =>
// ...
globalConfiguration.UseFilter(new AutomaticRetryAttribute { Attempts = 0 });
// ...
}); https://stackoverflow.com/questions/66458426
复制相似问题