Significant I wouldn’t know how to say it. The mechanisms are very different, but they serve for more or less the same thing, at least if the Task.Run()
is used to solve the same problem.
Obviously the way to use it is quite different, especially if you want to be notified of progress, but the result does not change much.
The BackgroundWorker
would not have been created if . NET had the await
from the beginning. It’s more modern, it’s the right way to do it, it’s better thought out and it’s a more general mechanism. Certainly the most modern way is simpler to write and for me it is more intuitive.
There’s nothing wrong with continuing the old way if you really prefer, but is considered obsolete.
Of course if you compare the Task.Run()
context does not give, it is more powerful, flexible and general. The comparison only fits in a very specific form of its use.
Example of operation that does not lock the UI:
private async void buttonGeraBoletos_Click(object sender, EventArgs e) {
await Task.Run(() => GeraBoletos());
MessageBox.Show("Tudo gerado");
}
I put in the Github for future reference.
You can do it in parallel too, which can end much faster.