Windows form's refresh method does notwork

G

Guest

My windows form "Form1" has one Button "button1" and one TextBox "textBox1".
When I click button1, it do a job for each file in a directory. The job
include some platform invoke call. Before processing a file, I set
textBox1's Text property as filename of the file processed, and call
this->refresh() to refresh the form.

Every thing seems OK.
But, if the process time for some file is a little long (say 10 seconds) and
during processing I click at the form, the cursor becomes Cursors.Wait .
After that, the textBox1 stop refresh the filename untill all the jobs are
done.
All the jos are well done except stop refreshing.

How to fix it. Thanks

AJang
 
S

shumaker

I have seen similar behavior when updating text boxes in a loop which
is within a button handler. The processing continues, but the form
stops refreshing, a side affect is that my processing will complete
much faster since the GUI seems to not be repainted or updated
repeatedly. My guess is that an event that involves user interaction
interupts the processing of events, so that the form can finish
handling the current event. So your Click event causes the Wait cursor
so that the user knows that their interactions cannot be processed.

Possible things to try: Set the cursor to Wait yourself before you
begin processing files, so that at the least the user will hopefully
not try to click. I believe the events still fire however. You could
possible also set the entire form to Enabled = false to prevent event
handling. I'm not sure if the refreshing will still occur though.
Then at the end of processing you set the cursor back and enable the
form again.


This is similar to something I read about MouseMove, your MouseMove
event can fire only as fast as you can complete processing the event.
In other words, if your mousemove event handler is currently
processing, and another mousemove event is recieved, the event is not
queued, but instead discarded since processing cannot begin on it.
 
M

Marc Gravell

You could try moving the work onto a background thread? This would leave the
UI available for painting; you would, of course, need to sync the access to
the UI (since the background thread can't talk directly to the controls).

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