C # Windows service development overview

Source: Internet
Author: User
Reference: http://www.taiwanren.com/blog/article.asp? Id = 8686

1. Use vs to create a Windows Service Project (the Chinese version is Windows Service). After the project directory is created, it is similar:
2. Switch to the design interface of services1.cs and open its Properties tab:

3. click the add installer link on the properties page. For more information, see the reference document. "after that, you will get two file service components and program. CS. to create a service, you must first add a dedicated installation component. This step is also very simple. Select the service component and switch to the design mode. Right-click and choose add installer to generate the installation file, switch to the design mode. here you will see two components: serviceinstaller and processinstaller. There is not much to note here, most of which are about setting the service name, description, and other information, there are only two places to note. one is starttype. There are three options: automatic, manual, and disabled. if You Want To Enable Automatic startup, select automatic once. another attribute that needs to be noted is account. Select User. Generally, select local system."

4. Write your own business logic code
5. Compile the program and install the service. This article provides a better generation script (yourservicename is the name of your own Service): 1 net stop yourservicename
2 copy/y "$ (targetdir)" $ (projectdir) bin"
3 "% SystemRoot % \ Microsoft. NET \ framework \ v2.0.50727 \ installutil.exe"/U $ (projectdir) bin \ $ (targetfilename)
4 "% SystemRoot % \ Microsoft. NET \ framework \ v2.0.50727 \ installutil.exe" $ (projectdir) bin \ $ (targetfilename)
5. Net start yourservicename
6

6. debugging. debugging of services is very troublesome. There are a lot of articles on the Internet. The "process appending" in Visual Studio debugging should be able to meet most of the requirements. if you want to debug the onstart and onstop methods, you need some other methods, which are not described here (I have not understood ).

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.