As you are working in the UI anyway why use a backgroundworker - just update the progress bar within the loop.
This CP article shows how to display text (percentage complete) "on" the progress bar -
Add the Percent (or Any Text) into a Standard Progress Bar Control[
^]
As the article is in C# I've converted it for you
Private Sub UpdateProgressBar(ByVal percent As Integer)
Dim percentText As String = percent.ToString() + "%"
Dim font As Font = SystemFonts.DefaultFont
ProgressBar1.Value = percent
Using gr = ProgressBar1.CreateGraphics()
Dim X As Single = ProgressBar1.Width / 2 - (gr.MeasureString(percentText, font).Width / 2.0F)
Dim Y As Single = ProgressBar1.Height / 2 - (gr.MeasureString(percentText, font).Height / 2.0F)
gr.DrawString(percentText, font, Brushes.Black, New PointF(X, Y))
End Using
End Sub
I tested my conversion using a standard ProgressBar control(
ProgressBar1
above) using the following code
ListBox1.Items.Clear()
Dim maxValue = 200000
Dim displayInterval = 5000
ProgressBar1.Maximum = 100
For i = 0 To maxValue
ListBox1.Items.Add(i)
If i Mod displayInterval = 0 Then
UpdateProgressBar(i * 100 \ maxValue)
End If
Next
Note that I don't change the display for every single loop - there is not much point - see
displayInterval
above. Play about with the value until you get the effect you desire