Creation of 1.windows Service
vs2012 Add Project Windows service
2. Main code
protected override void OnStart (string[] args) {System.Timers.Timer timer1 = new System.Timers.Timer ( ); Timer1. Interval = 3000;//interval time timer1. Elapsed + = new System.Timers.ElapsedEventHandler (stuadd);//The handler timer1 that is executed during the interval. AutoReset = true;//The System.Timers.Timer.Elapsed event is raised at the end of each interval, if only the first throw is set to false timer1. Enabled = true; }
protected override void OnStop () {File.appendalltext (@ "D:\ServiceLog.log", String. Format ("Stop time: {0}\r\n", DateTime.Now.ToString ())); }
3. Installation
CMD C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe The detailed address of the service you created \ your service. exe
4. Commissioning
Want to debug first your service has to be installed successfully
Start your service now in the service
1, Control Panel "management tool" service "Find your service right click" Start
In the VS tool "add" find your service add up "click OK
Create installation debugging for Windows service