C# Hangfire多台服务器

C# Hangfire多台服务器,c#,.net-core,hangfire,C#,.net Core,Hangfire,我正在构建一个.net核心web应用程序,在服务器端,我正在为计划任务和长期运行任务添加hangfire。在Startup.cs文件中,我添加了: services.AddHangfire(x => x.UseSqlServerStorage(Configuration.GetConnectionString("DefaultConnection"))); 在配置函数中,我添加了以下内容: app.UseHangfireServer(); app.UseHangfireDashboard

我正在构建一个.net核心web应用程序,在服务器端,我正在为计划任务和长期运行任务添加hangfire。在Startup.cs文件中,我添加了:

services.AddHangfire(x => x.UseSqlServerStorage(Configuration.GetConnectionString("DefaultConnection")));
在配置函数中,我添加了以下内容:

app.UseHangfireServer();
app.UseHangfireDashboard();
现在的问题是,每当我运行应用程序时,仪表板中都会出现一个新的服务器实例。


有没有办法确保只有一台服务器在运行?或者,如果我可以在停止应用程序(IIS)时关闭服务器,并在运行应用程序时再次启动服务器,则应为每个服务器创建单独的队列。请查看此页面:

这似乎解决了一些问题。它应该清除所有在过去15秒内未处于活动状态的服务器。我目前拥有这是我的应用程序startup.cs。感觉不是正确的解决方案,但受其提供的限制

        // Clean up Servers List
        Hangfire.Storage.IMonitoringApi monitoringApi = JobStorage.Current.GetMonitoringApi();
        JobStorage.Current.GetConnection().RemoveTimedOutServers(new TimeSpan(0, 0, 15));

        app.UseHangfireServer(new BackgroundJobServerOptions
        {
            WorkerCount = 1,
            Queues = new[] { "jobqueue" },
            ServerName = "HangfireJobServer",
        });

        RecurringJob.AddOrUpdate("ProcessJob", () => YourMethod(), AppSettings.JobCron, TimeZoneInfo.Local, "jobqueue");

根据当前版本的 不需要调用
app.UseHangfireServer()
inside
public void Configure()
(至少文档中没有包含它)

相反,在
public void ConfigureServices(IServiceCollection服务)
使用


这将消除第二个服务器实例

过一段时间后应删除旧实例。正确。。。谢谢你的回答
services.AddHangfire
services.AddHangfireServer