First intimate contact with Windows services

  
                

Every time you turn on your computer, Windows XP starts more than 80 services, and the average user knows little about these services running in the background. What exactly do they do? Do I really need all of these services? This tutorial will show you which services are required to run and which services do not have to be running. Start our first intimate contact with the windows service.

In many applications, you need to do windows services to operate the database, such as

(1) some very slow database operations I don't want to do it all at once, I want to do it slowly through the service timing, such as timing database backup, etc.

(2) Using windows service to do Host

in .net Remoting Vs.net we can build its windows service in a few minutes, very simple

Let's talk about the steps

1. Create a new project

2. From one available Select Windows Service from the list of project templates

3. The designer opens in design mode

4. Drag a Timer object from the component table of the toolbox onto the design surface (note: Be sure to use Timer from the list of components instead of from the Windows Forms list.

5. Set the Timer property, Interval property 200 milliseconds (5 times database operation in 1 second)

6. Then add the function for this service

7. Double-click this Timer. Then write some database operation code inside, such as

SqlConnection conn=new SqlConnection("server=127.0.0.1;database=test;uid=sa;pwd=275280");

SqlCommand comm=-new SqlCommand("insert into tb1 ('111',11)",conn);

conn.Open();

comm.ExecuteNonQuery();

conn.Close();

8. Switch this service to Design View

9. Right-click on Design View and select “Add Installer”
>

10. Switch to the design view of the ProjectInstaller you just added

11. Set the properties of the serviceInstaller1 component:

1) ServiceName = My Sample Service

2 StartType = Automatic

12. Set the properties of the serviceProcessInstaller1 component Account = LocalSystem

13. Change the path to the bin\\Debug folder where your project is located (if you Release mode compilation is in the bin\\Release folder)

14. Execute the command “InstallUtil MyWindowsService.exe&rdq Uo; register this service to make it a suitable registry entry. (InstallUtil this program in the WINDOWS folder \\Microsoft.NET\\Framework\\v1.1.4322 below)

15. Right click on the desktop “My Computer", select “Manage” Management Console

16. In the "Services & Applications" section of the "Services and Applications" section, you can find that your Windows service is already included in the service list

17. Right click on your service and select Start to start your service.

The crux of the problem is that we can't do without these services. Many of the features of Windows XP are implemented through these services. Simply put, you can think of these services as programs that perform system tasks in the background, such as getting automatic updates or managing print jobs. The biggest difference from the general application is that they all run in the "background", so you basically don't feel their existence.

Copyright © Windows knowledge All Rights Reserved