✅ BackgroundWorker getting progress
I have a winform applications and with this I have put a ProgressBar on it. I was manually changing the progress inside functions using
progressBar.Value = <value>
but now that I run my functions in the background using BackgroundWorker, changing that progress is a little harder than I thought. If I am not mistaken the code below is defined as a 'Delegate Invocation' and I use it to run the function I would like to track progress of:
How can I give progress better?6 Replies
Why harder?
The worker thread u pass the current progress value
i.e.:
Then on the report event u update the ui
there is a full sample here
https://learn.microsoft.com/en-us/dotnet/api/system.componentmodel.backgroundworker?view=net-8.0
Thank you will try this
And read this...I keep ignoring the documentation. My bad
you should not be using BackgroundWorker @SparkyCracked
you should instead use Task.Run, CancellationToken, and IProgress
Task.Run vs BackgroundWorker: Intro
This is an introductory post for a new series that I’ll be doing comparing BackgroundWorker to Task.Run (in an async style). I always recommend Task.Run, and I have already written a long post describing why, but I still see some developers resisting the New Way of Doing Things (TM). So this will be a short series where I’ll compare the code sid...
they're much nicer to use, and are applicable outside of GUIs
Ok I see
I think thats why I am having issues with my events as well.
It's really killing me. Task.Run was so much better
The main reason I use background worker in this case is just to understand it a little more as the company I am at used it in the code they wrote, and I wanted to see if it was useful.
I think imma try improve the existing code they have to
Task.Run
instead of BGWorker
Thanks for the help @jcotton42 and @leowest, let the learning continue :copium: