2011-03-12 81 views
0

我打電話從BackgroundWorker的下面的代碼,但不是設置所需的文本,它的應用程序添加標題lisbox 有什麼不對的地方安全的跨線程調用錯誤

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 

回答

2

你拿起形式的Text屬性當您調用委託(...New Object() {[Text]} ...)。您想在代表電話中發送sStatus參數,而不是:

If Me.lsbLog.InvokeRequired Then 
    Dim d As New SetTextCallback(AddressOf SetStatus) 
    Me.lsbLog.Invoke(d, New Object() {sStatus}) 
    ''# ...and so on