# Dashboard in Windows Service (without owin)

**URL:** <https://discuss.hangfire.io/t/dashboard-in-windows-service-without-owin/4339>\
**Category:** question\
**Tags:** postgres, dashboard\
**Created:** [February 9, 2018, 11:32am UTC](https://discuss.hangfire.io/t/dashboard-in-windows-service-without-owin/4339 "2018-02-09T11:32:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sarsik87](https://avatars.discourse-cdn.com/v4/letter/s/f0a364/32.png) [@sarsik87](https://discuss.hangfire.io/u/sarsik87)\
**Post date:** [February 9, 2018, 11:32am UTC](https://discuss.hangfire.io/t/dashboard-in-windows-service-without-owin/4339/1 "2018-02-09T11:32:00Z")

</div>

I use Hangfire in Windows Service with descriptions from

[http://docs.hangfire.io/en/latest/background-processing/processing-jobs-in-windows-service.html](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 🙂

---

<div class="post-metadata">

**Author:** ![Hans\_Engelen](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.hangfire.io/hans_engelen/32/1513_2.png) [@Hans\_Engelen](https://discuss.hangfire.io/u/Hans_Engelen)\
**Post date:** [February 14, 2018, 1:36pm UTC](https://discuss.hangfire.io/t/dashboard-in-windows-service-without-owin/4339/2 "2018-02-14T13:36:06Z")

</div>

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](http://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.

---

<div class="post-metadata">

**Author:** ![sarsik87](https://avatars.discourse-cdn.com/v4/letter/s/f0a364/32.png) [@sarsik87](https://discuss.hangfire.io/u/sarsik87)\
**Post date:** [February 19, 2018, 7:05am UTC](https://discuss.hangfire.io/t/dashboard-in-windows-service-without-owin/4339/3 "2018-02-19T07:05:13Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Hans\_Engelen](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.hangfire.io/hans_engelen/32/1513_2.png) [@Hans\_Engelen](https://discuss.hangfire.io/u/Hans_Engelen)\
**Post date:** [February 19, 2018, 10:47am UTC](https://discuss.hangfire.io/t/dashboard-in-windows-service-without-owin/4339/4 "2018-02-19T10:47:56Z")

</div>

Yes I figured that was what you meant.

First suggestion would be to use topshelf (see [nuget.org](http://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](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](https://msdn.microsoft.com/en-us/library/windows/desktop/cc307223(v=vs.85).aspx)

---

<div class="post-metadata">

**Author:** ![sarsik87](https://avatars.discourse-cdn.com/v4/letter/s/f0a364/32.png) [@sarsik87](https://discuss.hangfire.io/u/sarsik87)\
**Post date:** [February 24, 2018, 7:36pm UTC](https://discuss.hangfire.io/t/dashboard-in-windows-service-without-owin/4339/5 "2018-02-24T19:36:59Z")

</div>

Thank you very much for your help.
