[C # Windows Service] Getting started with "1,
[C # Windows Service] Getting started with "1"
Directory:
1.[C # Windows Service] Getting started with "1"
2.[C # Windows Service] INI configuration file
I. tools:
VS2015 + NET Framework4.5.
Ii. Operations:
1. Create a windows Service Project:
2. Modify windows Services:
3Preview the windows service code structure:
4Windows Service generation and release:
Iii. Code:
1. Test code:
Using ClassLibrary1; 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 {public Service1 () {InitializeComponent ();} protected override void OnStart (string [] args) {Thread thread = new Thread (delegate () {try {for (int I = 0; I <1000; I ++) {LogHelp. writeLog ("Service Startup" + I) ;}} catch (Exception ex) {LogHelp. writeLog ("service startup failed" + ex) ;}}); thread. name = "thread Test 1"; thread. isBackground = true; thread. start () ;}protected override void OnStop (){}}}
2. bat file code
Install the 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:
Record every day, code every line of code