Creating a simple Windows service
A Windows service always maps back to an executable file that's stored on the local hard drive. Although that executable could host a sophisticated program such as a Windows Communication Foundation service, here we'll create one that's much simpler. Our service will simply write to a log file periodically.
Visual Studio provides a project template for creating a Windows service. Go to File | New | Project | Windows | Windows Service.
Once you've created this new project, right-click on the Service1.cs
file in the SolutionExplorer and select ViewCode. The C# code that you'll see displays a class, here named Service1
, that is derived from System.ServiceProcess.ServiceBase
. It overrides the OnStart
and OnStop
methods.
These are the methods that every Windows service must implement so that they can be started and stopped by the Service Control Manager (SCM). The SCM is a process that tracks which services are installed and monitors their individual status. Later...