I have configured hangfire in webapi based project to initiate backgrond job .I have done below mentioned configuration for hangfire
Webapi Project Configuration for Hangfire
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);
}
Now I want to process background jobs (which will initiate from webapi project) using window services .I have created window service according to below mentioned code but service is unable to pickup job.Dashboard shows job is always in eneque. Is there any special configuration required which I am missing
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();
}
}