一旦您的背景工作者的進度達到100%,背景工作者的RunWorkerCompleted事件將觸發。
編輯 - 增加了代碼示例
Dim WithEvents bgWorker As New BackgroundWorker With { _
.WorkerReportsProgress = True, _
.WorkerSupportsCancellation = True}
Private Sub bgWorker_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles bgWorker.DoWork
For i As Integer = 0 To 100
'Threw in the thread.sleep to illustrate what's going on. Otherwise, it happens too fast.
Threading.Thread.Sleep(250)
bgWorker.ReportProgress(i)
Next
End Sub
Private Sub bgWorker_ProgressChanged(ByVal sender As System.Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles bgWorker.ProgressChanged
If e.ProgressPercentage Mod 10 = 0 Then
MsgBox(e.ProgressPercentage.ToString)
End If
End Sub
Private Sub bgWorker_RunWorkerCompleted(ByVal sender As System.Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles bgWorker.RunWorkerCompleted
MsgBox("Done")
End Sub