Windows Forms App: Refreshing UI During Execution.

  • Thread starter Thread starter Frankie
  • Start date Start date
F

Frankie

I'm writing a small C# Windows Forms application. As it does its processing,
I set the .Text property of a Label - so I can know the status of the
ongoing execution. Even though I set the property several times throughout
the execution, I don't see any but the last one - and even then I see it
only after all execution has completed. Is there some way to cause the Label
to display the .Text immediately when I set it?

Thanks!
 
Hi,

Calling Application.DoEvents() during your processing (after updating the label
text for example) allows the application to process any queued events like the
one that repaints the label. See the MSDN documentation of this method for more
information.

Best regards,

Rodger

Achieve Planner time management software - Project/task outliner with calendar
<http://www.effexis.com/achieve/planner.htm>

Sequence Diagram Editor - Draw sequence diagrams faster
<http://www.SequenceDiagramEditor.com>
 
You can force the repaint using yourLabel.Refresh() as soon as you change the
text.

cheers
 
Hi,

The "correct" way to go is do the processing in a worker thread. then using
Control.Invoke to force a method to run in the UI thread and update the
interface.


Cheers,
 
Back
Top