我正在显示当前在我的页面上运行的hangfire服务器列表.
我在控制台应用程序中运行hangfire服务器,但问题是当我没有运行我的控制台应用程序仍然hangfire api返回hangfire服务器.
此外,当我跑我的控制台应用程序多次,我得到3-4迟发型服务器虽然我只有1迟发型服务器控制台应用程序运行.
Mvc申请:
IMonitoringApi monitoringApi = JobStorage.Current.GetMonitoringApi();
var servers = monitoringApi.Servers().OrderByDescending(s => s.StartedAt);
Run Code Online (Sandbox Code Playgroud)
控制台应用程序:Hangfire服务器
public static void Main(string[] args)
{
var sqlServerPolling = new SqlServerStorageOptions
{
QueuePollInterval = TimeSpan.FromSeconds(20) // Default value
};
GlobalConfiguration.Configuration.UseSqlServerStorage("ConnectionString", sqlServerPolling);
// Set automatic retry attempt
GlobalJobFilters.Filters.Add(new AutomaticRetryAttribute { Attempts = 0 });
// Set worker count
var options = new BackgroundJobServerOptions
{
WorkerCount = 1,
};
using (var server = new BackgroundJobServer(options))
{
Console.WriteLine("Hangfire Server1 started. Press any key to exit...");
Console.ReadKey();
} …Run Code Online (Sandbox Code Playgroud)