Beginning of "C#windows service" "One"

Source: Internet
Author: User

Beginning of "C#windows service" "One"

First, tools:

Vs2015+net Framework4.5.

Second, Operation:

1. Create a new Windows Service project:

2. Modify Windows Services Related content:

3. Preview the Windows Service Code structure:

4. Windows Service Generation and publishing:

Third, the code:

1, test code:

Using classlibrary1;using system;using system.collections.generic;using system.componentmodel;using System.Data; Using system.diagnostics;using system.linq;using system.serviceprocess;using system.text;using System.Threading; Using System.threading.tasks;namespace windowsservicetest{public partial class Service1:servicebase {Publ        IC Service1 () {InitializeComponent ();            } protected override void OnStart (string[] args) {thread thread = new Thread (delegate ()                        {try {for (int i = 0; i <; i++) {                    Loghelp.writelog ("service start" + i); }} catch (Exception ex) {Loghelp.writelog ("service start failed" + ex)                ; ;            }            }                ); Thread.            Name = "thread Test 1"; Thread.            IsBackground = true; Thread.       Start (); } protected override void OnStop () {}}} 

  

2. bat file Code

Installation Service Code: SC Delete windowsservicetestsc create windowsservicetest start= auto binpath= D:\www\Debug\ WindowsServiceTest.exe SC description windowsservicetest "by eadily" Pause Uninstall Service code: net stop WINDOWSSERVICETESTSC Delete Windowsservicetest

  

Iv. Summary:

Keep track of every bit of the day, code good every line

Beginning of "C#windows service" "One"

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.