Developing Windows Services using Visual Studio .NET Explained - Part 1






2.75/5 (7 votes)
An overview and step by step guide to developing, using and debugging a windows service
Introduction
One of the most difficult task for a entry to mid-level .NET programmer is debugging a .NET Windows Service while it is live. Even if you do have a development server that you can use, debugging existing code may seem a mysterious task at first. I remember a few years back when I was researching this topic on the web, no one gives you a straight and simple answer about this topic. So here is my attempt at simplifying this topic a bit.
Windows Service Architecture
- Service Application: This type application is basically the actual Windows .NET Service that runs under Services.
- Service Controller Application: This type of application enables you to control the behavior of an existing application, start, stop, pause and continue a service.
- Service Control Manager: This is a utility that comes with Windows that enables you to control all services that are installed on a computer. It can be found at "Control Panel > Administrative Tools > Services".
Namespaces
Registry Information
The registry location that contains a list of all services running on a Windows Machine is:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\
Here is how a typical registry entry looks when a .NET Service is installed:
The most notable one is the "ImagePath" entry, which contains the path to the executable that runs the service. This value can be change to point to different versions of the service executable for testing purposes.
Important Notes
Methods Available
The following is a list of Methods that can / have to be overriden in order to run the service successfully or run a Service Controller Application:
- Methods of Service Base Class (to Override)
- OnStart()
- OnPause()
- OnStop()
- OnContinue()
- OnShutDown()
- OnCustomCommand()
- OnPowerEvent()
- Methods of Service Controller Class
- Close()
- Continue()
- ExecuteCommand()
- Pause()
- Refresh()
- Start()
- Stop()
Click HERE to go to Part 2 of this article.
Pete Soheil
DigiOz Multimedia
http://www.digioz.com/