namespace WinVJService { partial class WinVJService : ServiceBase { protected System.Timers.Timer timer; public WinVJService() { InitializeComponent(); } protected void InitializeTimer() { if (timer == null) { timer = new System.Timers.Timer(); timer.AutoReset = true; timer.Interval = ReadAppSettingInterval(); timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed); } } private void timer_Elapsed(object source, System.Timers.ElapsedEventArgs e) { RunCommands(); } protected void RunCommands() { RefVJService.VJServiceSoapClient objJob = new RefVJService.VJServiceSoapClient(); // WebService Reference Object objJob.RunJob(); // Here calling Web Service method EventLog.WriteEntry(ServiceName + "VJ Service ran ok"); } protected double ReadAppSettingInterval() { double interval = 60000, tempInterval; //initialize to ten minutes. if (ConfigurationSettings.AppSettings != null && ConfigurationSettings.AppSettings["IntervalMinutes"] != null) { string intervalMin; intervalMin = ConfigurationSettings.AppSettings["IntervalMinutes"]; if (Double.TryParse(intervalMin, NumberStyles.Any, NumberFormatInfo.InvariantInfo, out tempInterval)) interval = tempInterval * 60000; } return interval; } protected override void OnStart(string[] args) { // TODO: Add code here to start your service. EventLog.WriteEntry(ServiceName + "VJ Service started"); InitializeTimer(); timer.Enabled = true; } protected override void OnStop() { // TODO: Add code here to perform any tear-down necessary to stop your service. EventLog.WriteEntry(ServiceName + "VJ Service stopped"); timer.Enabled = false; } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)