C backgroundworker progress bar not updating

In loading images function i am inserted the following code to show progress bar.

m_Dlg = new Prog Dlg(this); m_Dlg- For this, i wrote one function in progress bar class and set image index to that function.

The Background Worker is built around this idea, and therefore comes with the two events Progress Changed and Run Worker Completed.

The third event is called Do Work and the general rule is that you can't touch anything in the UI from this event.

But a thread (any thread) can only do one thing at a time.

Your code has priority over lower functions like updating so when you start loading the images all resource of your thread go to doing so, and the UI will 'frees' and not update since something else (the loading function) is using it.

Any suggestions why the Progress Bar isnt updated when function runs. Background Worker hasn't worked in my case, got some Strange index out of bound exception, but couldn't figure out why it was thrown.

This will be raised every time the Progress Changed(int, object) or Progress Changed(int) function is called, the int will be your progress (in percentages or whatever you like) and the optional object can be used to pass along more information.

The solution to all of this is the use of multiple threads, and while C# makes this quite easy to do, multi-threading comes with a LOT of pitfalls, and for a lot of people, they are just not that comprehensible.

This is where the Background Worker comes into play - it makes it simple, easy and fast to work with an extra thread in your application.

By default, each time your application executes a piece of code, this code is run on the same thread as the application itself.

This means that while this code is running, nothing else happens inside of your application, including the updating of your UI.

Leave a Reply