VB.NET - BackgroundWorker.RunWorkerCompleted 的 'sender' 是什么?
VB.NET - What is the 'sender' of BackgroundWorker.RunWorkerCompleted?
我注意到 BackgroundWorker.RunWorkerCompleted
处理程序调用中有一个 ByVal sender As Object
参数,我很好奇当 BackgroundWorker 完成其工作时发送者会是什么。我的直觉告诉我这将是 BackgroundWorker,但 BackgroundWorker.RunWorkerCompleted Event MSDN article 上似乎没有任何明确的声明来证实这一点。我也搜索过,但我似乎也找不到答案。
谁能教教我?
你的问题让我很好奇:
根据你的问题,答案是是。
我尝试了一些测试:
我尝试的第一个是:
Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
MsgBox(sender.Name.ToString)
End Sub
知道sender
的名字是什么。
这个给我一个错误。
System.Reflection.TargetInvocationException
但使用:
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
提示Yeah!
,确认sender
就是BackgroundWorker1
。
供您参考:
HOW TO: Determine the Sender of an Event Without Using the Control.Name Property
希望对您有所启发。
我注意到 BackgroundWorker.RunWorkerCompleted
处理程序调用中有一个 ByVal sender As Object
参数,我很好奇当 BackgroundWorker 完成其工作时发送者会是什么。我的直觉告诉我这将是 BackgroundWorker,但 BackgroundWorker.RunWorkerCompleted Event MSDN article 上似乎没有任何明确的声明来证实这一点。我也搜索过,但我似乎也找不到答案。
谁能教教我?
你的问题让我很好奇:
根据你的问题,答案是是。
我尝试了一些测试:
我尝试的第一个是:
Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
MsgBox(sender.Name.ToString)
End Sub
知道sender
的名字是什么。
这个给我一个错误。
System.Reflection.TargetInvocationException
但使用:
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
提示Yeah!
,确认sender
就是BackgroundWorker1
。
供您参考: HOW TO: Determine the Sender of an Event Without Using the Control.Name Property
希望对您有所启发。