Updating form with text during long process
-
I have a form with a label (name = labelStatus) that I would like to update during a lengthy process (e.g. while scanning all files on drive - show filename).
void TimeConsumingMethod() { string fileName = "C:\Temp\A.txt"; // Do some stuff here labelStatus.Text = string.Format("Searching {0}", fileName); // Do more stuff here // Finally finished. }
It doesn't seem to update the label until the method finishes. I've tried to invalidate the form after setting the new text, but that really doesn't make a visible difference. How can I accomplish this? --G -
I have a form with a label (name = labelStatus) that I would like to update during a lengthy process (e.g. while scanning all files on drive - show filename).
void TimeConsumingMethod() { string fileName = "C:\Temp\A.txt"; // Do some stuff here labelStatus.Text = string.Format("Searching {0}", fileName); // Do more stuff here // Finally finished. }
It doesn't seem to update the label until the method finishes. I've tried to invalidate the form after setting the new text, but that really doesn't make a visible difference. How can I accomplish this? --GAs far as i know you have to update the label your self: labelStatus.Text = "The stuff you want"; labelStatus.Update(); or: labelStatus.Text = "The stuff you want"; labelStatus.Update(); this.Update(); and finally you can write the following before the lenghty process starts: Application.DoEvents(); Hope it works!
-
As far as i know you have to update the label your self: labelStatus.Text = "The stuff you want"; labelStatus.Update(); or: labelStatus.Text = "The stuff you want"; labelStatus.Update(); this.Update(); and finally you can write the following before the lenghty process starts: Application.DoEvents(); Hope it works!
zagzagzag wrote: Hope it works! :-D Thanks -- this worked perfectly.