我已经在基于 webapi 的项目中配置了 hangfire 来启动后台作业。我已经完成了下面提到的 hangfire 配置
Hangfire 的 Webapi 项目配置
public static void ConfigureHangfire(IAppBuilder app)
{
GlobalConfiguration.Configuration.UseSqlServerStorage("Connnection_Dev");
IUnityContainer unityContainer = UnityConfig.GetConfiguredContainer();
UnityJobActivator unityJobActivator = new UnityJobActivator(unityContainer);
GlobalConfiguration.Configuration.UseActivator(unityJobActivator);
app.UseHangfireDashboard();
var options = new BackgroundJobServerOptions { WorkerCount = Environment.ProcessorCount * 20 };
app.UseHangfireServer(options);
}
现在我想使用窗口服务处理后台作业(将从 webapi 项目启动)。我根据下面提到的代码创建了窗口服务,但服务无法获取作业。仪表板显示作业始终在 eneque 中。是否需要我缺少任何特殊配置
public partial class Service1 : ServiceBase
{
private BackgroundJobServer _server;
public Service1()
{
InitializeComponent();
GlobalConfiguration.Configuration.UseSqlServerStorage("Connnection_Dev");
}
protected override void OnStart(string[] args)
{
IUnityContainer unityContainer = UnityConfig.GetConfiguredContainer();
UnityJobActivator unityJobActivator = new UnityJobActivator(unityContainer);
var options = new BackgroundJobServerOptions { WorkerCount = Environment.ProcessorCount * 20 ,
Activator=unityJobActivator};
_server = new BackgroundJobServer(options);
_server.start();
}
protected override void OnStop()
{
_server.Dispose();
}
}