I have list of files(widgets) that I need to do some work on. I want to do it in async manner so my interface stays responsive. I want to update UI with progress. Here is my prototype code. How do I accomplish this? I assume I need to utilize threading, but I also don’t want to span all the threads at the same time, one by one is fine.
void Process()
{
var documents = GetDocuments();
foreach(document in documents)
{
ProcessDocument(
document,
status => this.TextBox.Text += status);
}
}
void ProcessDocument(Document document, Action<string> onCompleted)
{
}
You can use the BackgroundWorker class to process operation asynchronous in Windows Forms projects.