The establishment of a simple Windows Service

Source: Internet
Author: User

With vs.net, we can establish its Windows service in a few minutes, which is very simple.

The following are the steps
1. Create a project
2. Select Windows Services
3. Slave Toolkit Components Drag a timer object in the table to the design surface, using the system. Timer. Time
4. Set the timer attribute. The interval attribute is 200 milliseconds (5 database operations are performed in 1 second)
5. Double-click the timer and write some database operations in it. Code For example
Sqlconnection conn = new sqlconnection ("Server = Wagner. 0.0.1; database = test; uid = sa; Pwd = 275280 ");
Sqlcommand comm =-New sqlcommand ("insert into tb1 values ('000000', 11)", Conn );
Conn. open ();
Comm. executenonquery ();
Conn. Close ();
6. Set this service Program Switch to design view
7. Right-click the design view and select "add installer"
8. Switch to the design view of the newly added project installer.
9. Set the attributes of the serviceinstaller1 component:
1) servicename = My Sample Service
2) starttype = Automatic startup)
10. Set the serviceprocessinstaller1 component's attribute account = LocalSystem
11. Change the path to the bin \ debug folder of your project (if you compile in release mode, in the bin \ release folder)
12. Execute the command "installutil.exe mywindowsservice.exe" to register this service so that it can create a suitable registration item. (Installutil is in the Windows Folder \ Microsoft. NET \ framework \ v1.1.4322)
13. Right-click "my computer" on the desktop and select "manage" to access the computer management console.
14. In the "services" section of "services and applications", you can find that your Windows services are included in the Service list.
15. Right-click your service and choose start to start your service.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.