I am stuck updating a progressbar from a different thread. I did get it running in the simplest way, but then cleaning the code gets me stuck. Multithreading for a progressbar and code locations (vb.net)? Ask Question 4. Vb.net multithreading progress-bar backgroundworker invokerequired. Share| improve this question. Edited Feb 4 '16. 1 of 9 Background Worker in.NET 2.0. Don't want to perform that task in the main (event handling) thread. Some cleaning up, our code looks like this. Here is the code to update the progress bar.
Here's one way.by passing a reference to the BackgroundWorker into the Progress Form: Public Class Form1 Private Sub Button1Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click Button1.Enabled = False Dim progress As New frmProgress(Me.BackgroundWorker1) progress.ShowDialog Button1.Enabled = True MessageBox.Show('Done!'
You can never update a UI component from a different thread, so the correct approach should be the other way around. You need to implement you logic on background threads and report back to the UI thread when you need to change it. To do so easily, the.Net framework comes with the built-in class.
It allows you to run your code on another thread and provides a number of methods that will provides reporting and canceling abilities from the UI thread. See the MSDN page on the BackgroundWorker for more explanations as well as details examples: Regards Yoni.