Executes an operation on a separate thread.
DoWork event occurs when RunWorkerAsync is called.
RunWorkerCompleted event occurs when the background operation has completed, has been canceled, or has raised an exception.
Example:
Imports System.ComponentModel
Imports System.ThreadingModule Module1
Public Sub backWork()
Dim worker As New BackgroundWorker()
AddHandler worker.DoWork, AddressOf DoWork
AddHandler worker.RunWorkerCompleted, AddressOf bg_RunWorkerCompleted
worker.RunWorkerAsync()
End Sub
Private Sub DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs)
' some work
Thread.Sleep(5000)
End Sub
Private Sub bg_RunWorkerCompleted(ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs)
MsgBox("Background worker completed", vbInformation, "Background worker")
End Sub
End Module