我已经在基于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项目启动)。我已根据下面提到的代码创建窗口服务但是服务无法取回作业。仪表板显示作业始终处于灌注状态。是否需要我缺少的特殊配置
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();
}
}