Creating a windows service itself is a hassle that includes various aspects of it like configuration, install-uninstall, recovery, start mode etc. Managing this settings is either can be achieved manually or by writing bunch of batch/command files that helps in deployment and management of windows services.
Recently, I came across an ultimate .Net OSS library that provides control almost everything related to a Windows service. The library is known as “TOPSHELF”, the contribution creds of this library goes to Travis Smith, Charles patterson and few more awesome contributors. See the well managed documentation of this project here.
How this library tool makes a difference creating a windows service? Let’s try to create a windows service:
The above code is expected to run as windows service. Now conventionally to make it a window service one must add a Window service file type then WindowsInstaller etc. Rather I’ll be using Topshelf library for hassle free setup:
Windows services made easy
That’s it now when I run this code my service will run as Console. Without Topshelf I would have create a separate class to run the service as console. But now I can see in few lines of code things are quite awesome. Let’s simply press F5 in visual studio to run the above code:
Running as Console service
Let’s simply press F5 in visual studio to run the above code:
Installation of window service
Simply call the generated .exe file with argument
Let’s take a look at the services window. Goto Run –> Services.msc.
And I can see my service is started and running. How cool is it..I’m sure this kinda stuff will make DevOPs guys happy. There are plenty of option that are configurable easily using this library, I can say OOS stack of .Net is coming into picture and helping developers making softwares better an better everyday.