Safe cross thread calling error
Am calling the following code from backgroundworker, but instead of setting the desired text, it add the application caption to the lisbox what is wrong with it
Private Sub SetStatus(ByVal sStatus As String)
If Me.lsbLog.InvokeRequired Then
Dim d As New SetTextCallback(AddressOf SetStatus)
Me.lsbLog.Invoke(d, New Object() {[Text]})
'// Me.Invoke(Sub() SetStatus(sStatus))
Else
If Mid$(LCase$(sStatus), 1, 4) = "sent" Then
tslSent.Text = "Sent:" & FormatNumber(lSent, 0, TriState.False)
Else
lsbLog.Items.Add(sStatus)
End If
开发者_如何学运维 End If
End Sub
You pick up the form's Text
property when you invoke the delegate (...New Object() {[Text]} ...
). You want to sent the sStatus
argument in the delegate call instead:
If Me.lsbLog.InvokeRequired Then
Dim d As New SetTextCallback(AddressOf SetStatus)
Me.lsbLog.Invoke(d, New Object() {sStatus})
''# ...and so on
精彩评论