VB.NET - What is BackgroundWorker.RunWorkerCompleted "sender"?

I noticed that there is an argument ByVal sender As Object

in the handler call BackgroundWorker.RunWorkerCompleted

and I am curious what the sender will be when the BackgroundWorker exits. My gut instinct tells me it will be a BackgroundWorker, but there doesn't seem to be an explicit expression in the BackgroundWorker.RunWorkerCompleted Event MSDN article to confirm this. I have also searched SO, but I cannot find an answer either.

Can someone enlighten me?

+3


source to share


1 answer


Your question piqued my curiosity:

As per your question, the answer is YES.

I tried some testing:

The first one I tried is:

    Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
       MsgBox(sender.Name.ToString)
    End Sub

      

to find out what the name is sender

.

This is giving me an error.



System.Reflection.TargetInvocationException

But using:

    Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
        If sender Is BackgroundWorker1 Then
            MsgBox("Yeah!")
        End If
    End Sub

      

He requested Yeah!

, confirming that sender

it is BackgroundWorker1

.

For reference: HOW to: Determine the sender of an event without using the Control.Name property

I hope this enlightened in some way.

+4


source







All Articles