Stop Hangfire gracefully

Hi, i’ve found different threads about this argument but no solution…
When i stop Hangfire (for example during publish), i want that it continues to execute current jobs until they ends, for example giving a maximum of 2 minutes.

Hangfire run on a IHostedService in .NET 6

I’ve tried with:

  • .Server.WaitForShutdown(new TimeSpan(0, 2, 0)); // it always wait 2 minutes, not what i waant
  • .Server.Dispose(); (setting “StopTimeout” to 2 minutes) // But after 15 seconds Hangfire it’s stopped.



I too would like to see Hangfire stop accepting new messages, and appear offline for any scheduling purposes, while giving some time for the current running processes to complete, even going so far as to hold up the system shutdown cycle until all running processes are complete, then allowing the pod to gracefully shutdown.

As opposed to shutting down all running processes abruptly and rescheduling them for retry.

– my two pennies

1 Like

This is an old post but still a feature I’d like to see. So, I’m bumping it up.