The standard tool for creating a Windows service is the Visual Studio. Net template called Windows Service.
It is necessary
The main benefit of this Windows Service tool is that it automatically creates references to the correct classes and name categories using inheritance and modifying the required methods
Make sure that you understand the sequence of steps for creating your service: - correctly defining the service name of the service; - creating the necessary installers; - performing an override; - defining the OnStop and OnStart code; - defining the configuration method for the created service.
Use the Properties dialog box to set the desired name for the service you are creating. Note that the selected service name must match the name used by the class installer application. Any change to the value of the name used implies an update of the class installer application.
Use the necessary parameters to define the properties and methods of functioning of the created service: - True - in the CanStop section - to allow receiving requests that interrupt execution; - True - in the CanShutDown section - to allow receiving notifications when the computer is turned off that call the OnShutDown procedure; - False - in the CanPauseAndContinue section - to prohibit the interruption and resumption of the service, or True - to allow these actions; - False - in the CanHandlePowerEvents section - to prohibit the service from receiving notifications about changes in the computer's power state, or True - to allow receiving such notifications; - False - in the section AutoLog - to prohibit recording a report of actions performed by the service in the event log, or True - to enable event logging.
Call the code editor tool and enter the required processing values for the OnStop and OnStart procedures. Modify the parameters of the values of the methods to be changed in functionality and add the necessary installers for the service being created.
Expand the Build menu and enter the Build Solution command without trying to use the F5 function key to start the service. Install the created service.