c# - JobStorage.Current 属性值尚未初始化。您必须在使用 Hangfire 客户端或服务器 API 之前设置它
问题描述
我在 mvc 应用程序中使用 hangfire。我正在向用户发送他/她的约会提醒。我已经在我的应用程序中安装了hangfire。我在 startup.cs 类中配置了hangfire。但是当我运行该应用程序时,它会产生以下错误 JobStorage。当前属性值尚未初始化。您必须在使用 Hangfire 客户端或服务器 API 之前设置它。
using Hangfire;
using Hangfire.SqlServer;
using Microsoft.Owin;
using Owin;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using UKC.Data.Infrastructure;
using UKC.UI.Helper;
[assembly: OwinStartup(typeof(UKC.UI.App_Start.Startup))]
namespace UKC.UI.App_Start
{
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
ConfigureAuth(app);
GlobalConfiguration.Configuration
.UseSqlServerStorage("DbEntities");
app.UseHangfireDashboard();
app.UseHangfireServer();
}
}
}
解决方案
用于在 Asp.net 核心中初始化
public static void InitializeHangFire()
{
var sqlStorage = new SqlServerStorage("connectionString");
var options = new BackgroundJobServerOptions
{
ServerName = "Test Server"
};
JobStorage.Current = sqlStorage;
}
推荐阅读
- python - 如何使用 aws cli 提取表中的所有数据?
- javascript - NodeJs 如何识别阻塞(同步)和非阻塞(异步)代码?
- python - “audio = r.listen(source, timeout=10000)”中的超时函数不适用于 Python 中的 SpeechRecognition
- python - 如何从python中dict的键值分配多个变量值?
- firebase - facebookAuthCredential.idToken 在 Flutter 中为空
- c++ - 类函数无法访问c ++(初学者问题)
- python - tinydb 搜索、插入、更新错误
- spring-boot - 这是spring @Retryable 应该如何工作的吗?
- c++ - OpenCV C ++如何组合两个图像并保存为一个位置
- r - 发布针织实验室报告 - 编码错误?