Make Hangfire always in running mode for core

Tags: #<Tag:0x00007faff534e2f0>

I am using Hangfire in core application. I am using recurring jobs that running every 15 minutes. But after some time it stops their working. When i am enter url in browser then its again start working. I have done some google for it and found some settings are needed. I need some code stuff for core. Please help me.

You should set your IIS application pools to not shutdown.

We use PRTG to hit the Hangfire servers and the dashboards to keep them up and running. If you have a monitoring services you could do the same.

Or there is this tool which does this same thing, no monitoring.

I have done everything suggested to make sure my application pool never shuts down, from setting the timeout to zero, to setting it to “AlwaysRunning”, to maintaining the Integrated app pool; nothing helps. In the .NET framework verison of Hangfire, there used to be a bootstrapper class you could hook into the Global.asax, and then hook up the ApplicationPreLoad settings in IIS to make sure the app would start/restart gracefully. That worked. Nothing I’ve tried for .NET Core has worked so far. This is becoming a huge problem for my organization, as we switched over to .NET Core, and now we can’t move anything to production because our recurring jobs stop every 29 hours when the application pool recycles. Has anyone found a surefire solution to this OTHER than setting up a separate process that pings the Hangfire API every so often? If you need a separate recurring job handler to queue your Hangfire recurring job handler, that is a problem!

Ah-ha, I think I may have stumbled upon the special sauce required to make this work:

  1. Set Application Pool to:
    .NET CLR version: .NET CLR Version v4.0.30319
    Managed pipeline mode: Integrated
    (Normally for a .NET Core app, you’d use No Managed Code, but if you do that, the application preload won’t work.)
  2. In Application Pool Advanced Settings:
    Start Mode: Always Running
    Idle Time-out (minutes): 0
  3. For your Hangfire application, go to Configuration Editor system.webServer/applicationInitialization:
    doAppInitAfterRestart: True
  4. Also in Config Editor system.webServer/applicationInitialization, open up the Collection… ellipsis, go to Add, and enter in the following:
    hostName: {URL host for your Hangfire application}
    initializationPage: {path for your Hangfire dashboard, like /hangfire}

Now when I recycle my app pool, the app starts back up again. Whew!