1. Create a new Windows service program.
2, click on this service class, add a Timer control from the toolbox, right the timer control named Timerorderdeductiondetailjob,enable set to True.
3. Right-click this service class to set the Timer control's start interval in the OnStart method.
protected override void OnStart (string[] args) { //TODO: Add code here to start the service. this.timerOrderDeductionDetailJob.Interval = +; }
4. Double-click the timer time control to register an event
private void Timerorderdeductiondetailservice_elapsed (object sender, System.Timers.ElapsedEventArgs e) { W Orking ();//method to execute}
5, the method of implementation
private void Working () {New Exceptionhelper (). Writelog ("Start orderdeductiondetailjob Job" + DateTime.Now.ToString ("Yyyy-mm-dd HH:mm:ss"), @ " Orderdeductiondetailjob "); this.timerOrderDeductionDetailJob.Enabled = false; try {orderdeductiondetailjob Order = new Orderdeductiondetailjob (); Order.execute (); } catch (Exception ex) {StringBuilder sberror = new StringBuilder (); Sberror.append ("Error time:" + DateTime.Now.ToString ("Yyyy-mm-dd hh:mm:ss") + Environment.NewLine); Sberror.append ("Error file:" + ex.) Source + Environment.NewLine); Sberror.append ("error message:" + ex.) Message + Environment.NewLine); Sberror.append ("method to raise the error:" + ex.) TargetSite + Environment.NewLine); Sberror.append ("The trace that caused the error:" + ex.) StackTrace + Environment.NewLine); New Exceptionhelper (). Writelog (sberror.tOstring (), @ "Orderdeductiondetailjob"); } this.timerOrderDeductionDetailJob.Enabled = true; New Exceptionhelper (). Writelog ("End orderdeductiondetailjob Job" + DateTime.Now.ToString ("Yyyy-mm-dd HH:mm:ss"), @ "Orderdeductiondetailjob "); New Exceptionhelper (). Writelog ("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *" + Environment.NewLine + Environment.NewLine + ENVIRONMENT.N Ewline, @ "Orderdeductiondetailjob"); }
6, add the service installation program, click on the service class, the right to add the installation program.
7. Click on the Installer class.
8, change the installation service name, StartType changed to Automatic.
9, ServiceProcessInstaller1 Right-click Property account changed to LocalSystem.
10, compile this service, install. There are two types of installation methods:
(1), windows+r (Run command prompt), input cmd
Run command: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe (space) window item bin\release under. exe file address
Example: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe (space) F:\chenfeilong\Project\Aidaiji Awin\adj. Job.orderdeductiondetailservice\bin\release\adj. Job.OrderDeductionDetailService.exe
(2), SC Create service name binpath= (space) "Windows Service item bin\release under. exe file Address" Start=auto