Put Your Apps on the TopShelf

Many of my projects end up using a Windows service or three to host background processes.  Over the years, I’ve developed a common-sense strategy of setting up a server class to contain the functionality that implements start and stop methods.  I then create minimal command-line and windows service hosts to instantiate the server class and call start and stop when appropriate.  This gives me a command-line server that can be conveniently started from the debugger and a windows service application for use in the production environment.  Of course, this also means using InstallUtil when it comes time to install the service.

Today I stumbled across a much nicer solution in the open source TopShelf project.  It lets me build a console application using about ten lines of code that hosts my server for development and provides a command-line to install as a Windows service so InstallUtil is not required.   Highly recommended!

%d bloggers like this: