Recently I created a posting outlining a project template for a WinForms application. This posting outlines a new project template that provides the elements for the creation windows service in F#. The template can be found on the Visual Studio Gallery:
When the template is installed you get the following template added to your F# folder when creating a new F# project:
This template provides several projects elements:
The MyService.fs source file provides the implementation of the service. The template code provides the structure for the OnStart and OnStop methods and shows how an EventLog can be created and referenced:
The entry point for the program is defined in the Program.fs source file:
As you can see for a service the entry point is defined using the [<EntryPoint>] attribute.
Finally, so that the installutil tool correctly installs the service, an Installer class is also defined:
The template version installs the service using the Local System account. However, this can easily be changed.
Finally, the template creates a command file that can be used to install and un-install the service. When running this command file you will need a command prompt running with elevated privileges.
Once again, hopefully you will find this template useful.
Written by Carl Nolan