
You need to marshall the interaction back to the UI thread to prevent this. Any background process (threaded) that tries to directly interact with the UI will give you cross-threading problems. Just a couple of points to clarify from your last post. Public Class Form1 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Me.ProgressBar1.Maximum = 10 End Sub Private Sub btnHeavyTask_Click(sender As Object, e As EventArgs) Handles btnHeavyTask.Click Debug.Print("Starting to count now") BackgroundWorker1.WorkerReportsProgress = True BackgroundWorker1.RunWorkerAsync() mainThreadTask() End Sub Private Sub mainThreadTask() Dim i As Integer = 0 Do Until i = 15 Me.txtHeavyTask.AppendText(vbCrLf + i.ToString) Me.txtHeavyTask.Refresh() (500) i += 1 Loop Me.txtHeavyTask.Text = "Done" End Sub Private Sub BackgroundWorker1_DoWork(sender As Object, e As ) Handles BackgroundWorker1.DoWork Dim i As Integer = 1 Do Until i = 10 Debug.Print(i.ToString) (1000) BackgroundWorker1.ReportProgress(i) i += 1 Loop Debug.Print("Counted to " & (i).ToString) BackgroundWorker1.ReportProgress(i) End Sub Private Sub BackgroundWorker1_ProgressChanged(sender As Object, e As ) Handles BackgroundWorker1.ProgressChanged Me.ProgressBar1.Value = e.ProgressPercentage.ToString Me.ProgressBar1.Refresh() End Sub End Class Note: The code below is just a test I'm performing so I can take the structure and expand it to a real-world, time-consuming, stored-proc.

Of course, I'd like the progressbar to update during the counting. Interestingly, the two counts do occur at the same time (which is the intent.win!) but the progressbar doesn't change at all until after the BackgroundWorker has finished.


One runs directly from the form (in the main thread) and another is performed by a BackgroundWorker.
