You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Mike Schenk edited this page May 5, 2016
·
4 revisions
Using Visual Studio
Create a Console Application.
.NET 3.5 and above is supported
Install the EasyServiceHost package
Use Package Manager Console or
Install-Package EasyServiceHost
Optionally, change Main to return int
Create a bootstrap class
This class will become the entry point to your service.
The class can be named anything. It must have a public default (no-argument) constructor. It must implement the IManagedService interface:
classBootstrap:IManagedService{publicvoidStart(IServiceHosthost){//TODO: start a new thread to do the work of your service.}publicvoidStop(TimeSpantimeLimit){//TODO: stop the thread within the time specified in timeLimit.}}
The constructor and the Start method both run while the Windows Service Control Manager is waiting for a response to the start command. If you have initialization that could take longer than a couple of seconds, your should start a new thread to run it.
Call ManagedHost.RunOne(args) from Main
This will handle and installation, uninstallation, and running your service depending on the command-line arguments supplied.