protected override void OnStart(string[] args) { log = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + @"\OperationLog.txt", true); WaitList = WaitListOnStop.Load(); Conection.DesktopServerProcedure(); Conection.WebOpen(); //When process starts if (WaitList.Count >= 1) { CheckList(); } this.StartMainFunction = new Timer(3000); // 3seg this.StartMainFunction.AutoReset = true; this.StartMainFunction.Elapsed += new ElapsedEventHandler(this.timer1_Elapsed); this.StartMainFunction.Start(); this.StartWaitList = new Timer(1800000);// 30min this.StartWaitList.AutoReset = true; this.StartWaitList.Elapsed += new ElapsedEventHandler(this.timer2_Elapsed); this.StartWaitList.Start(); LogWriteLine("Service starded"); log.AutoFlush = true; }
protected override void OnStop() { Conection.DeskConection.Close(); Conection.WebConection.Close(); LogCheckCreation(); if (WaitList.Count >= 1) { LogWriteLine("There are unfinished O.S to be checked yet. Saving data..."); string end = WaitListOnStop.Save(WaitList); if (end == "") { LogWriteLine("data save successful. file path(" + AppDomain.CurrentDomain.BaseDirectory + @"\datawait"); } else { LogWriteLine("FAIL TO SAVE DATA. NO INFORMATION WILL BE LOAD LATE. MAJOR ERROR:" + end); } } LogWriteLine("Service stoped"); log.Flush(); log.Close(); }