How can you update the GUI when using a delegate function as new Thread? I am trying to update a label, that would tell the user the state of application's progress, but this way, it only updates once it is done, not while doing it.
public partial class Form1 : Form
{
private void button1_Click_1(object sender, EventArgs e)
{
new Thread(new ThreadStart(delegate()
{
int currentFile= 0;
int allFiles = Source.FilePaths.Count;
foreach (var path in Source.FilePaths)
{
var file = new File(path, Source.DestDirPath, System.IO.File.ReadAllLines(path));
file.saveSQL();
currentFile++;
int rounded = (int)((currentFile/ allFiles) * 100);
CompletionLabel.Invoke(new MethodInvoker(() => Completion.Text = "Completion: " + rounded + "%"));
}
})).Start();
}
}
I would like to keep it as simple as possible, because it is just a simple converter, that converts some text file to sql files.