You are customizing a Windows Form to update a database asynchronously in a method named WorkHandler. You need to ensure that the form displays a message box to the user
that indicates the success or failure of the update. Which code segment should you use?
A.
Private Sub StartBackgroundProcess() AddHandler bgwExecute.DoWork, AddressOf WorkHandler AddHandler bgwExecute.RunWorkerCompleted, AddressOf CompletedHandler bgwExecute.RunWorkerAsync()End SubPrivate Sub CompletedHandler(ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs) Dim result As Boolean = CType(e.Result, Boolean) If result = True Then MessageBox.Show(“Update was successful”) Else MessageBox.Show(“Update failed”) End IfEnd SubPrivate Sub WorkHandler(ByVal sender As Object, ByVal e As DoWorkEventArgs) ‘… e.Result = TrueEnd Sub
B.
Private Sub StartBackgroundProcess() AddHandler bgwExecute.ProgressChanged, AddressOf CompletedHandler Dim tsBackground As New ThreadStart(AddressOf WorkHandler) bgwExecute.RunWorkerAsync(tsBackground)End Sub Private Sub ProgressHandler(ByVal sender As Object, ByVal e As ProgressChangedEventArgs) Dim result As Boolean = CType(e.UserState, Boolean) If result = True Then MessageBox.Show(“Update was successful”) Else MessageBox.Show(“Update failed”) End IfEnd SubPrivate Sub WorkHandler() ‘… bgwExecute.ReportProgress(100, True)End Sub
C.
Private Sub StartBackgroundProcess() AddHandler bgwExecute.RunWorkerCompleted, AddressOf CompletedHandler Dim tsBackground As New ThreadStart(AddressOf WorkHandler) bgwExecute.RunWorkerAsync(tsBackground)End SubPrivate Sub CompletedHandler(ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs) Dim result As Boolean = CType(e.Result, Boolean) If result = True Then MessageBox.Show(“Update was successful”) Else MessageBox.Show(“Update failed”) End IfEnd SubPrivate Sub WorkHandler() ‘… bgwExecute.ReportProgress(100, True)End Sub
D.
Private Sub StartBackgroundProcess() AddHandler bgwExecute.DoWork, AddressOf WorkHandler AddHandler bgwExecute.RunWorkerCompleted, AddressOf CompletedHandler bgwExecute.RunWorkerAsync()End SubPrivate Sub CompletedHandler(ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs) Dim result As Boolean = CType(e.Result, Boolean) If result = True Then MessageBox.Show(“Update was successful”) Else MessageBox.Show(“Update failed”) End IfEnd SubPrivate Sub WorkHandler(ByVal sender As Object, ByVal e As DoWorkEventArgs) ‘…
bgwExecute.ReportProgress(100, True)End Sub