pause

  • Thread starter Thread starter RobcPettit
  • Start date Start date
R

RobcPettit

Hi, Ive got a text box on a form and my program collect values. When
its running id like it to update my text box after each 50 values. How
do I get the program to pause, update the textbox then continue. I can
do the count ok, and get the values it doesnt update the textbox
though. I using if( x - y == 50) textbox = etc.
Regards Robert
 
In a tight loop (which it sounds like you are) the nasty way is to call
Application.DoEvents(); after each 50.

This gets the job done, but isn't really nice; a better (but more complex)
way involves using a background thread and eventing, or a background worker
component (which does the same under the bonnet).

Marc
 
Thanks for a quick response, Ill have a read up on background threads.
Regards Robert
 
Fair enough...

Also - I kinda assumed in your original post that the textbox itself wasn't
the problem; using the grungy DoEvents() approach, this would look something
like:

int counter = 0;
while(someLoopCondition) {
DoSomethingInteresting();
counter++;
if(counter % 50 == 0) {
someTextBox.Text = counter.ToString();
Application.DoEvents(); // hate hate hate
}
}

Marc
 
Back
Top