Code To Gracefully Stop & Restart?

Hello,

I’m using the RecurringJobManager as follows:

JobStorage.Current = new SqlServerStorage(“DefaultConnection”, options);
var manager = new RecurringJobManager();
RecurringJob.RemoveIfExists(“Job Name Here”);

manager.AddOrUpdate(“Job Name Here”", Job.FromExpression(() =>
DoStuff.RunNow()), Cron.MinuteInterval(1));

I’m also running BackgroundJob.Enqueue(…)

What I want to do is to shut down everything HangFire related for maintenance or any other reason.

The reason why I’m asking this is I’ve seen some Recurring and Background jobs get “lost” when I updated my production environment application server. I made changes to my ASP.NET web application and no database changes.

I know, in theory, they should all restart.

My goal here is to have a button in my web app that runs C# code to gracefully pause everything. Then, after the update, a button to click to restart everything. If you have an example, I’d appreciate the link.

I appreciate your help.

Thanks,

Don Juan

Does HangFire shut down gracefully when IIS is stopped?