【问题标题】:Hangfire ASP.NET Core packagesHangfire ASP.NET Core 包
【发布时间】:2018-12-26 03:13:57
【问题描述】:

我已经安装了软件包:

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 上运行。

【问题讨论】:

  • 不,因为即使使用这些建议的解决方案,我也遇到了问题。
  • RecurringJob.AddOrUpdate 看起来像一个静态方法。您没有初始化 asp.net 核心管道
  • 稍后尝试将RecurringJob.AddOrUpdate(() => Console.Write("Easy!"), Cron.Minutely);移动到app.UseHangfireServer();

标签: c# asp.net-core hangfire


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-02-20
    • 1970-01-01
    • 2020-02-17
    • 1970-01-01
    • 1970-01-01
    • 2019-12-15
    • 1970-01-01
    相关资源
    最近更新 更多