Looping a Background Worker Task
<p>I have some code inside a background worker <code>DoWork</code> event which check if a process is running or not. The code in the <code>DoWork</code> does the following:<br/>
-> If the process is not running, check again twice<br/>
-> If the process is running, check if it is responding<br/>
-> If the process is running and respoding, do nothing<br/>
-> If the process is running and not responding, restart the process<br/></p>

<pre><code> void bgworker_DoWork(object sender, DoWorkEventArgs e)
        {
            int numberTrials = 0;
            bool isNotRunning = false;
            while (isNotRunning = (someProcess.Length == 0) &amp;&amp; numberTrials &lt; 3)
            {
                Debug.WriteLine(String.Format("numTrial = {0}", numberTrials.ToString()));
                Thread.Sleep(3000);
                ++numberTrials;
            }
            if (isNotRunning)
            {
                Debug.WriteLine("Start Task");
                someProcess.Start();
            }
            else
            {
                if(!someProcess.IsKioskResponding)
                {
                    Debug.WriteLine("Kill Task");
                }
            }
        }
</code></pre>

<p>The above thing runs fine but I have to loop the above <code>DoWork</code> task for every 3 minutes. Would it be a good thing to keep the above looping task in a timer that has an interval of 3 minutes? (In that way I would have to take care of <code>Thread.Sleep x numberTrials</code> not to exceed the Timer's interval). Any thoughts on this?</p>
