I need to call a function inside a window service periodically. c# vs 2008 interval should be set from config file which is the best way to do? Please suggest
while (Service1.serviceStarted)
{
CheckFile();
Thread.Sleep(60000);
}
Thread.CurrentThread.Abort();
or
private Timer timer;
private void InitializeTimer()
{
if (timer == null)
{
timer = new Timer();
timer.AutoReset = true;
timer.Interval = 60000 * Convert.ToDouble(
ConfigurationSettings.AppSettings["IntervalMinutes"]);
timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
}
}
<add key="IntervalMinutes" value="5" />
private void timer_Elapsed(object source,System.Timers.ElapsedEventArgs e)
{
RunCommands();
}
Thanks
Kj