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"