The first intimate contact with the Windows service

  
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 close contact with the windows service.
In many applications, you need to do windows services to operate the database and other operations, such as
(1) some very slow database operations, do not want to do it once I want to slowly do it through the service timing, such as timing for database backup, etc.
(2) Using windows service to do Host in .net Remoting. Using vs.net, we can build it in a few minutes. Windows service, very simple
Next step
1. Create a new project
2. Select Windows service from a list of available project templates
3. Designer will open in design mode
4. Drag a Timer object from the toolbox's component table onto the design surface (note: make sure to use Timer from the component list instead of the Windows Forms list)
5. Set the Timer property, Interval The property is 200 milliseconds (5 times database operation in 1 second)
6. Then add the function for this service
7. Double-click this Timer, and then write some database operation code inside, such as
SqlConnection conn= New SqlConnection("serv Er=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 & rdquo;
10. Switch to the design view of the ProjectInstaller just added
11. Set the properties of the serviceInstaller1 component:
1) ServiceName = My Sample Service
2) StartType = Automatic ( Boot automatically run)
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 compile in Release mode, then in the bin\\Release folder)
14. Execute the command “InstallUtil MyWindowsService.exe”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 & rdquo; select “ management & rdquo; you can call the computer 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 option to launch You can start your service.
The key to 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