I'm almost completely virgin in threading / backgroundworkers etc.
I am trying to do this:
While the background BL is operating I'd like the UI not to hang, but the continuation of the execution of the next BL method should only execute after the first one has ended and the UI has been updated with the message I'd like to present.
I'd like the slimmest, simplest way to do this. using .Net 4.5, so I believe we're talking Tasks, right?
I've read dozens of Stackoverflow articles and consulted uncle google and aunt MSDN, but it's overwhelming - there are many ways to do this, and I'm a bit lost.
Thanks in advance.
Whatever you're talking about are fairly simple to do with async/await. Since you said you're new to multithreading, I recommend you to read and make yourself familiarize with it. Here is a good start and this
I assume you can implement #1 yourself and you only need guidance in implementing rest. So, I'll not be talking about it in my post.
Theoretically you need a collection with the list of work needs to be done, then start one by one after the previous one is completed.
To give some code sample
List<WorkItem> workItems = ...;//Populate it somehow
private async Task DoWorkMain()
{
foreach (var item in workItems)
{
await DoWork(item);
//WorkItem completed, Update the UI here,
//Code here runs in UI thread given that you called the method from UI
}
}
private Task DoWork(WorkItem item)
{
//Implement your logic non blocking
}
Then somewhere from the UI call
await DoWorkMain();
WorkItem
is a class which holds data about the work to be done.