pause

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
 
M

Marc Gravell

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
 
R

RobcPettit

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

Marc Gravell

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
 

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

Top