Search code examples
hangfire

Why Hangfire server shuts down?


I have a .net 5 application that uses Hangfire. The problem is that as soon as the application completes it's startup, the hangfire server shuts down. If I place a breakpoint on the last line of Startup.cs, the hangfire server is alive. There are no errors logged.

What might be the cause of this?

Below is the code used for adding Hangfire.

public void ConfigureServices(IServiceCollection services)
{

 services.AddHangfire(config =>
            {
                config.UseSqlServerStorage(configuration.GetConnectionString("HangfireDefaultConnection"), new SqlServer.SqlServerStorageOptions
                {
                    CommandBatchMaxTimeout = TimeSpan.FromMinutes(5),
                    SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5),
                    QueuePollInterval = TimeSpan.Zero,
                    UseRecommendedIsolationLevel = true,
                    DisableGlobalLocks = true,
                    SchemaName = "dbo.WR_Hangfire",
                });
            });
....

}

public void Configure(IApplicationBuilder app)
{
...
 app.UseHangfireServer();
...
}


Solution

  • Turns out app.UseHangfireServer(); is deprecated and that was the problem. Solved by registering the server with services.UseHangfireServer().