John
If (Not DbControl.VerifyXmitrIntegerity(ErrMsg, worker)) Then
msg =
"Failed verifying transmitter!" & vbCrLfmsg &=
"Error: " & ErrMsg Throw New System.Exception(msg) Exit Sub End IfPrivate Sub backgroundWorker1_RunWorkerCompleted(ByVal sender As Object, _ ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) _ Handles BackgroundWorker1.RunWorkerCompleted Dim ExMsg As String = [String].Empty If e.Error IsNot Nothing Then
Results.BackColor = Color.Red
' First, handle the case where an exception was thrown.Results.ForeColor = Color.White
Results.Text =
"Failed"MessageBox.Show(e.Error.Message,
"Error Alert!!") Call DisconnectCommunicationsNoWorker() ElseIf e.Cancelled ThenResults.BackColor = Color.Orange
' Next, handle the case where the user aborted the operation.Results.ForeColor = Color.White
Results.Text =
"Aborted" Call DisconnectCommunicationsNoWorker() ElseResults.BackColor = Color.Green
' Finally, handle the case where the operation succeeded.Results.ForeColor = Color.White
Results.Text =
"Passed" End If Me.ProgressLabel.Value = 0 Call Me.EnableButtons() Call Me.EnableMenu() Call SharedSubroutines.ChangeButtonState(Me.btnAbort, Enums.ButtonState.Disable) End Sub
Threading in Visual Studio 2005: DoWork Subroutine
David Rudd
What is the reason for creating the 'worker' variable instead of using 'backgroundWorker1' Directly
In this code example you created the 'worker' variable.
' Get the BackgroundWorker object that raised this event.
Dim worker As System.ComponentModel.BackgroundWorker = _ CType(sender, System.ComponentModel.BackgroundWorker)mep_fuso
The reason I was using the worker variable was because alot of the work was being done in a dll and I needed a way to abort the code. I did this by passing the worker id to all calls made to the DLL.
Thanks for the response
sgraber
e.Result = UpdateTransmitter(worker, e)
End SubDusty333
Private Sub backgroundWorker1_DoWork(ByVal sender As Object, _ ByVal e As System.ComponentModel.DoWorkEventArgs) _ Handles BackgroundWorker1.DoWork ' Get the BackgroundWorker object that raised this event. Dim worker As System.ComponentModel.BackgroundWorker = _ CType(sender, System.ComponentModel.BackgroundWorker) ' Assign the result of the transmitter update to the result property of the ' DoWorkEventArgs object. This is available to the RunWorkerCompleted ' eventhandler.
e.Result = UpdateTransmitter(worker, e)
End SubHope this will help
John
LynchburgRecord