I have a class for refreshing the text of a label:
class GUIDisplayer:IOutputter
{
Label label;
public GUIDisplayer(Label label)
{
this.label = label;
}
public void display(string text)
{
label.Text = text;
label.Refresh();
}
}
An instance of this class gets passed to another class in my Windows Forms app, where I use it for showing progress during a For loop:
public class BatchConverter
{
IOutputter outputter;
public BatchConverter(IOutputter outputter)
{
this.outputter = outputter;
}
public bool convertFiles(List<FileTransferData> fileTransferList,bool overwrite=true)
{
for (int index = 0; index < fileTransferList.Count; index++)
{
FileTransferData file = fileTransferList[index];
outputter.display(index + "/" + fileTransferList.Count + ": " + file.sourcePath);
//do some file conversion operations
}
return true;
}
}
When convertFiles()
is running, the label gets updated with the first call to outputter.display()
, but then the app just freezes with the blue busy circle until it's finished with the For loop. The For loop successfully writes to the output device with the outputter.display()
calls when I implement the IOutputter.display()
method using Console.WriteLine()
. I want the text in the label to refresh every time the For loop iterates; is there a way I can do that?