I have read that a 'BackgroundWorker' is designed to be replaced by Ansyc/Await.
Because I like the condensed look of Async/Await, I am starting to convert some of my BackgroundWorkers into Async/Await calls.
This is an example of the code I have (called from the UI):
public async void RunFromTheUI()
{
await OtherAction();
}
public async void OtherAction()
{
var results = await services.SomeRemoteAction();
foreach (var result in results)
{
result.SemiIntenseCalculation();
Several();
Other();
NonAsync();
Calls();
}
SomeFileIO();
}
When I call RunFromTheUI
it will return almost immediately (as per the Async and Await design).
But when it resumes after services.SomeRemoteAction()
finishes it has a foreach
loop and another method call to run through.
My question is: If that loop is a performance hog will it freeze the UI? (Before I had it all in a Background worker thread, so it did not slow the UI down).
Note: I am targeting .Net 4.0 and using the Async Nuget Package.