Timer not working inside loop

  • Thread starter Thread starter Jay Stacy
  • Start date Start date
J

Jay Stacy

I have a timer on my form that works fine when I'm just
sitting there looking at the form. As soon as I click a
button that runs a routine that loops, the timer doesn't
fire. What I want to do is exit from the loop after a
certain time period if the loop exit condition is never
met. Basically something like this:

timer.start;
while((!timeout)&&(x<y))
{ do something to x and y}

//The timer routine would look something like this.
private timer_tick()
{ timeout = true;
timer.stop;
}
 
Hi Jay,
That's right. .NET uses windows timers which notifies the application for
ticks via windows messages. Since you are speening a loop in the main UI
thread the message loop is not executed and pfcourse no events fom the
timer, mouse keyboard, etc.

What you might want to do is to use worker thread for the lenghty operations
or to call Application.DoEvents() method periodically if you want to have
those events fired.

HTH
B\rgds
100
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top