Click here to Skip to main content
15,896,557 members
Articles / Programming Languages / C#

Switching From a BackgroundWorker To a Task - It's a Neater Solution, Particularly When Reporting Progress

Rate me:
Please Sign up or sign in to vote.
5.00/5 (10 votes)
17 Jan 2024CPOL1 min read 11.1K   22  
Why switch from the "traditional" BackgroundWorker to a Task? The old way works OK, but the new way generates "tidier" code which keeps stuff together (and needs less code)
I've used BackgroundWorkers for a long time - most of my apps use them to free up the UI from long running tasks, and they have a built in progress reporting mechanism which a "raw" Thread lacks. But I've recently realized that the Task class can do it as well, and in a really tidy way. So this tip shows you the old and new ways, so you can easily switch.

Views

Daily Counts

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
CEO
Wales Wales
Born at an early age, he grew older. At the same time, his hair grew longer, and was tied up behind his head.
Has problems spelling the word "the".
Invented the portable cat-flap.
Currently, has not died yet. Or has he?

Comments and Discussions