FOR LOOP within Callback procedure in System.Threading.Timer causes it to fire only ONCE
<p>At the moment I have a For loop  within a Callaback procedure :</p>

<pre><code>private void InitializeComponent()
{

var timer = new System.Threading.Timer(TimerProc, null, 60000, 60000);

}

public void TimerProc(object state)
{

    for (int i = 0; i &lt;= 6; i++)
    {
        //Do something here
    }

}
</code></pre>

<p>TimerProc only fires ONCE despite the fact that I have it set to repeat every 60000 milliseconds. It looks like that the operations within the loop are no longer executed after they are completed the first time around.</p>

<p>However, if I remove the For loop and have some other action like print to a console line or write to a text file then TimerProc repeats as expected.</p>

<p>Why is this the case and why does a loop with in a Callback procedure stop it from executing after its initial firing?</p>

<p>I have made a workaround by using a while(true) infinte loop and using the Thread.Timer to pause the process after x amount of milliseconds.</p>

<p>My new vised code with the while loop looks like this:</p>

<pre><code>private void InitializeComponent()
{

processthread = new Thread(new ThreadStart(DoSomething));
processthread.Start();

}

public void DoSomething()

{

  while(true)
  {
    for (int i = 0; i &lt;= 6; i++)
    {
           //do something here

    }
    Thread.Sleep(5000);
  }

}
</code></pre>

<p>I just want to know why callback procedure in the System.Thread.Timer cannot handle loops.</p>

<p>Cheers,</p>

<p>Stanley</p>
