首页 > 解决方案 > Hangfire ASP.NET Core 包

问题描述

我已经安装了软件包:

Hangfire.AspNetCore Hangfire.MemoryStorage.Core

这是我的代码:

using Hangfire;
using Hangfire.MemoryStorage;

public void ConfigureServices(IServiceCollection services)
{
    services.AddHangfire(c => c.UseStorage(GlobalConfiguration.Configuration.UseMemoryStorage()));
    services.AddMvc();
}

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

...

public static void Main(string[] args)
{
    RecurringJob.AddOrUpdate(() => Console.Write("Easy!"), Cron.Minutely);
}

但是,我收到错误:

JobStorage.Current property value has not been initialized. You must set it before using Hangfire Client or Server API.

我的应用程序正在运行ASP.NET Core

标签: c#asp.net-corehangfire

解决方案


Main方法之前运行ConfigureConfigureServices因此您尝试Hangfire在配置发生之前使用。


推荐阅读