How to write the service

How to write the service

The standard instrument of creation of a Windows service can be considered the Visual Studio.Net template named Windows Service. The main advantage of this tool is automatic creation of links to the necessary classes and categories of names using inheritance and change of the necessary methods.

Instruction

1. Make sure that the sequence of actions for creation of the service is clear to you: - correct definition of an office name of service; - creation of necessary installers; - performing redefinition; - definition of the OnStop and OnStart code; - definition of a method of a configuration of the created service.

2. Use the Properties dialog box for a task of a necessary name of the created service. Pay attention that the selected name of service without fail should match the name used by the application of installation of classes. Entering of any changes into value of the used name means updating of the application of installation of classes.

3. Use necessary parameters for determination of properties and ways of functioning of the created service: - True - in the section CanStop - for permission of receiving the requests interrupting execution; - True - in the section CanShutDown - for permission of obtaining the notifications at shutdown of the computer calling the OnShutDown procedure; - False - in the section CanPauseAndContinue - for an interrupt disable and resumption of work of service or True - for permission of these actions; - False - in the section CanHandlePowerEvents - for the ban of obtaining by service of notifications on changes in a power status of the computer or True - for permission of obtaining similar notifications; - False - in the section AutoLog - for the ban of record of the report of the operations performed by service in the event log or True - for permission of maintaining the event log.

4. Call the tool of a code editor and enter necessary values of processing for the OnStop and OnStart procedures. Change parameters of values of the methods which are subject to change of functionality and add necessary installers for the created service.

5. Open the Build menu and specify the Build Solution command, without trying to use a function key of F5 for start of service. Install the created service.

Author: «MirrorInfo» Dream Team


Print