I have created a .NET Framework 4.5 application using the Hangfire.Core
and Hangfire.SqlServe
r nuget packages. The code is pretty straight forward.
class Program
{
static void Main(string[] args)
{
GlobalConfiguration.Configuration
.UseSqlServerStorage("Server=localhost;Database=HangfireDb;User Id=username;Password=password");
BackgroundJob.Enqueue(() => ProcessData("process this"));
using (var server = new BackgroundJobServer())
{
Console.WriteLine("Hangfire Server started. Press any key to exit...");
Console.ReadKey();
}
}
public static void ProcessData(string data)
{
Console.WriteLine(data);
}
}
After running this program, I see the table schema is created in the database, and the [Job]
table gets populated with an entry for this method. However, I don’t know how to access the hangfire dashboard to view the job itself. I tried http://localhost/hangfire but that reports a 404 error. After some googling, I added the following Startup.cs
class in the project.
using Hangfire;
using Microsoft.Owin;
using Owin;
using System.Collections.Generic;
[assembly: OwinStartup(typeof(HangfireSample.Startup))]
namespace HangfireSample
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.UseHangfireServer();
app.UseHangfireDashboard("/hangfire");
}
}
}
I set up a break-point in the Configuration
method but it didn’t get hit and I still cannot access the hangfire dashboard. Any suggestions what I am doing wrong here?