Update Text from thread

J

joelcochran

I have a form with a text box (and I have tried this with labels,
listboxes, etc.) that I want to update from a thread. The thread is a
class that loops (say a thousand times) and randomly selects a string
from an array. Each time it selects another string, I want the
selected string to be shown on the calling form. The affect should be
that the text appears to be constantly changing until the final
selection is made.

The problem I'm having is that the text remains blank until the process
is complete. I have done this sort of thing (updating lists and
progress bars) before, but I can't figure out why this text won't
update. In fact, there is also a progress bar being updated at the
same time which is working perfectly.

I also tried invalidating the control, but that had no effect. In
debug, I have confirmed that the delegate method is receiving the
string, and the control Text property is being updated, so the
Threading is working correctly, it is just not showing the change on
the screen.

Any ideas?

Thanks,

Joel
 
J

joelcochran

I guess I posted too quickly... I figured it out a few minutes later...

The problem is that the thread is operating too quickly, so it's like
the calling form does not have time to redraw. I added a
Thread.Sleep(10) to my loop, and now it works exactly as I wanted...

Thanks,

Joel
 

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