Someone asked me to create a step by step guide on how to make a windows service that is easy to debug too. So here it is. You can do this in two ways. Either start by choosing the Windows Service template, chance the Application Type under MY Project –> Application to “Console Application” then select “Sub Main” in Startup Object. Add a Module, and add a function main to that. After that you can add a project installer under Service Class. Or if you want a bit more control you can start by creating a Windows Forms Application or Console Application and then add the Service things.
Create a Windows Application.
Add a reference to System.ServiceProcess and System.Configuration.Install
Add a class called ServiceManager with the following code
Add a new Class and call it something meaningful. This will be where you onStart onStop functions will be. I called it TestServiceControl
Add the following code to the Class
Rename Module1 to something meaningful (I called it mainModule ), and add the following code.
And that’s it. You can now more rapidly work with a Windows Service.
You can download this as a Microsoft Visual Studio 2010 solution here.