Dashboard in Windows Service (without owin)

I use Hangfire in Windows Service with descriptions from

http://docs.hangfire.io/en/latest/background-processing/processing-jobs-in-windows-service.html

But I don’t know how run dashboard (database is postgresql).
Plese help me :slight_smile:

You stated without OWin … Any special reason for that as you can quite comfortably run the Dashboard as a windows service in a self-hosted OWin instance (Microsoft.Owin.Hosting for instance which I believe under the hood is Katana) (i.e. no need for IIS etc).

I ask because I get the impression that you think OWin only works in conjunction with ASP.NET on IIS and this is not the case.

As with everything it comes with a list of things to consider on what the best option is for your specific scenario.

First of all I don’t want to use ASP and IIS. I can use OWIN in a Windows Service. But how should I do it?

Yes I figured that was what you meant.

First suggestion would be to use topshelf (see nuget.org). It is not a must but highly recommended imho for making Windows Services easy (especially the deployment and installation part, no need for a special setup up project).

This is what a typical Program.cs would look like (for topshelf just make a new console project in Visual Studio)

using Topshelf;
namespace MyDashboard
{
internal class Program
{
static void Main()
{
HostFactory.Run(x =>
{
x.Service(s =>
{
s.ConstructUsing(name => new Bootstrap());
s.WhenStarted(tc => tc.Start());
s.WhenStopped(tc => tc.Stop());
});
x.RunAsLocalSystem();
x.SetDescription(“Service Description”);
x.SetDisplayName(“Service Display Name”);
x.SetServiceName(“ServiceName”);
});
}
}
}

The Bootstrap.cs is easy:

using System;
using Microsoft.Owin.Hosting;
namespace MyDashboard
{
public class Bootstrap
{
private IDisposable _host;
public void Start()
{
var options = new StartOptions
{
Port = 8999
};
_host = WebApp.Start< Startup>(options);
Console.WriteLine();
Console.WriteLine(“Hangfire Server started.”);
Console.WriteLine(“Dashboard is available at http://localhost:8999/hangfire”);
Console.WriteLine();
}
public void Stop()
{
_host.Dispose();
}
}
}

And then the startup.cs class as last :

using Hangfire;
using Hangfire.Mongo;
using Owin;
namespace MyDashboard
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.UseErrorPage();
app.UseWelcomePage(“/”);
GlobalConfiguration.Configuration.UseMongoStorage(FILL_IN_STORAGE_INFO);
app.UseHangfireDashboard();
}
}
}

And hey presto…

ps. sure wish adding code to posts was easier on this forum, am I missing some trick to do it better ? Had to add a space here and there to make it stop hiding bits (especially around ‘<’ characters)

On a side note though, and this has nothing to do with Hangfire, but OWin selfhosting can be challenging. You might need to set up permissions if you are running the service under a non-admin account etc. See MSDN Article

Thank you very much for your help.