private void Timer1_Tick(object sender, ElapsedEventArgs e) { try { Library.WriteLog("Timer Ticked"); Library.ManageLongRunningTask(); } catch (Exception exception) { Library.WriteLog("Error on ticking windows service, excpetion details will follow - "); Library.WriteErrorLog(exception); } }
protected override void OnStop() { try { _timer1.Enabled = false; Library.WriteLog("Test Windows Service Stopped"); } catch (Exception e) { Library.WriteLog("Error on stopping windows service, excpetion details will follow - "); Library.WriteErrorLog(e); } }
protected override void OnStart(string[] args) { try { _timer1 = new Timer { Interval = 5000 }; // every 5 seconds _timer1.Elapsed += Timer1_Tick; _timer1.Enabled = true; Thread.CurrentThread.Name = "Main Thread"; Library.WriteLog("Test Windows Service Started"); } catch (Exception e) { Library.WriteLog("Error on starting windows service, excpetion details will follow - "); Library.WriteErrorLog(e); } }