C# How to call function inside a windows service at specified interval
<p>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</p>

<pre><code>  while (Service1.serviceStarted)
            {

                    CheckFile();
                Thread.Sleep(60000); 
            }

            Thread.CurrentThread.Abort();
</code></pre>

<p>or </p>

<pre><code>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);
    }
}



&lt;add key="IntervalMinutes" value="5" /&gt;



private void timer_Elapsed(object source,System.Timers.ElapsedEventArgs e)
{
    RunCommands();
}
</code></pre>

<p>Thanks </p>

<p>Kj</p>
