Developers familiar with WPF use
Dispatcher.Invoke to create a delegate for updating UI elements. The style is:
Dispatcher is not available in Windows Forms. So generally Windows Form developers rely mainly upon updating the UI elements in
ProgressChanged event handler of background worker. However, a simple and similar way of UI update would be nice as you may want several UI updates per progress change.
The solution might be known to many or should I say most of the prolific CodeProject developers. However I still find this question being asked in numerous forums and therefore have decided to post it here. If you already know this, great, if you do not, use it.
Using the Code
As the solution is simple, I would simply put the code. I guess nothing much is there to explain.
One important thing that you must remember while working with updating UI elements is that it is always preferred to update the elements from UI thread.
ProgressChanged is still the best place to update your UI . However it is a good practice to use this model even within
ProgressChanged to ensure trouble free element update.
Points of Interest
Doing things in simpler ways is also an efficient way. Developers working extensively on cross threading models like Port programming, Web cam and Image operations, remote methods might find this technique useful. I posted as usual for beginners to save them from "Thread Horror". Your discussions, suggestions and criticism are welcome as always.
gasshopper.iics is a group of like minded programmers and learners in codeproject. The basic objective is to keep in touch and be notified while a member contributes an article, to check out with technology and share what we know. We are the "students" of codeproject.
This group is managed by Rupam Das, an active author here. Other Notable members include Ranjan who extends his helping hands to invaluable number of authors in their articles and writes some great articles himself.
Rupam Das is mentor of Grasshopper Network,founder and CEO of Integrated Ideas Consultancy Services, a research consultancy firm in India. He has been part of projects in several technologies including Matlab, C#, Android, OpenCV, Drupal, Omnet++, legacy C, vb, gcc, NS-2, Arduino, Raspberry-PI. Off late he has made peace with the fact that he loves C# more than anything else but is still struck in legacy style of coding.
Rupam loves algorithm and prefers Image processing, Artificial Intelligence and Bio-medical Engineering over other technologies.
He is frustrated with his poor writing and "grammer" skills but happy that coding polishes these frustrations.