C # Writing Windows services

Source: Internet
Author: User

Project requirements:

The database has a table that holds the address of the file to be downloaded, and the service requires the rotation to download the downloaded file.

The table structure is as follows:

Process:

    1. vs-- file -- New project -->windows-->windows service

    1. Add Setup Service1.cs Design Right-click Add Installer

    1. Select the ServiceInstaller1 Right-click service name to fill in the Custom service name

Fill in Magicfilemonitorservice here

    1. Select ServiceProcessInstaller1 Right-click account to select LocalSystem, This is the account used when the service is installed

    1. Create the install and uninstall files install.bat and uninstall.bat in the root directory, and right--- Properties -- Copy to output directory select Always copy

    1. Install.bat Writing

%systemroot%\microsoft.net\framework\v4.0.30319\installutil.exe C:\QMDownload\MongoDBFileDown\bin\Debug\ mongodbfiledown.exe--This is the exe file directory

Net Start magicfilemonitorservice--Open service

sc config magicfilemonitorservice start= auto--set the service to run automatically

pause--pausing to view the installation status in the CMD window

    1. Uninstall.bat Writing

%systemroot%\microsoft.net\framework\v4.0.30319\installutil.exe/u C:\QMDownload\MongoDBFileDown\bin\Debug\ mongodbfiledown.exe--This is the exe file directory

Pause

    1. Add a Timer control to the Servic1.cs.

9. Join the main program (not listed in detail)

10. Installation program

Bin found install.bat right -- Run as Administrator

Attention:

1.install.bat must right-click the administrator to run

2.timer1_elapsed add logic, must add OnStar content or not work

Annex (VS2013): 2016-07-06

CSharp the entire process of writing Windows services. rar

Maigcfilemonitor.rar

C # Writing Windows services

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.