Threading in Visual Studio 2005: DoWork Subroutine

When I use Throw New System.Exception ("Oboy") it does not goto the background worker complete but rather tells me that my code does not handle the exception. This way of throwing the exception did work in the beta 2 version of VS2005. What I am I doing wrong

JohnSad



If (Not DbControl.VerifyXmitrIntegerity(ErrMsg, worker)) Then

msg = "Failed verifying transmitter!" & vbCrLf

msg &= "Error: " & ErrMsg

Throw New System.Exception(msg)

Exit Sub

End If

Private 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 Then

Results.BackColor = Color.Orange ' Next, handle the case where the user aborted the operation.

Results.ForeColor = Color.White

Results.Text = "Aborted"

Call DisconnectCommunicationsNoWorker()

Else

Results.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



Answer this question

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

    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 Sub


  • Dusty333


    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 Sub

    Hope this will help

    JohnSmile


  • LynchburgRecord

    This code seems fine, could you please post the complete DoWork method

  • Threading in Visual Studio 2005: DoWork Subroutine