In my experience, this is usually because the jobs previously failed so Hangfire automatically retries them when it gets a chance. (You can check if this is the case by looking in your database for jobs in the Failed
state.)
There are ways to modify this behavior if desired:
If you don’t want a job to be retried, place an explicit attribute with 0 maximum retry attempts value:
[AutomaticRetry(Attempts = 0)]
public void BackgroundMethod()
{
}
Use the same way to limit the number of attempts to the different value. If you want to change the default global value, add a new global filter:
GlobalJobFilters.Filters.Add(new AutomaticRetryAttribute { Attempts = 5 });
If you are using ASP.NET Core you can use the IServiceCollection extension method AddHangfire. Note that AddHangfire uses the GlobalJobFilter instance and therefore dependencies should be Transient or Singleton.
services.AddHangfire((provider, configuration) =>
{
configuration.UseFilter(provider.GetRequiredService<AutomaticRetryAttribute>());
}
Reference: Dealing with exceptions