Imports System.ComponentModel
Public Class Form2
Public WithEvents bg As BackgroundWorker
Private Sub bg_DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs) _
Handles bg.DoWork
Dim bw As BackgroundWorker = TryCast(sender, BackgroundWorker)
Dim pi As New ProgressInfo()
System.Threading.Thread.Sleep(1000)
pi.Actionstring = "Update the masterfile"
pi.ActionNumber = 1
bw.ReportProgress(10, pi)
System.Threading.Thread.Sleep(1000)
pi.Actionstring = "Update the masterfile finish"
pi.ActionNumber = 2
bw.ReportProgress(20, pi)
'Etc
End Sub
Private Sub bg_ProgressChanged(ByVal sender As Object, ByVal e As ProgressChangedEventArgs) _
Handles bg.ProgressChanged
Dim pi As ProgressInfo = DirectCast(e.UserState, ProgressInfo)
Label1.Text = pi.Actionstring
Label2.Text = pi.ActionNumber.ToString()
ProgressBar1.Value = e.ProgressPercentage
End Sub
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
bg = New BackgroundWorker()
bg.WorkerReportsProgress = True
bg.RunWorkerAsync()
End Sub
End Class
Public Class ProgressInfo
Public Property Actionstring() As String
Get
Return m_actionstring
End Get
Set(ByVal value As String)
m_actionstring = value
End Set
End Property
Public Property ActionNumber() As Integer
Get
Return m_actionNumber
End Get
Set(ByVal value As Integer)
m_actionNumber = value
End Set
End Property
Private m_actionNumber As Integer
Private m_actionstring As String
End Class