Update label from mainform class with backgroundworker from another class

后端 未结 3 468
[愿得一人]
[愿得一人] 2021-01-20 19:19

I have two classes.

Public Class MainForm

     Private Project As clsProject


Private Sub btnDo_Click
   ...
   Backgroundworker.RunWorkerAsync()

End Sub
         


        
3条回答
  •  难免孤独
    2021-01-20 20:10

    Try:

    Me.Invoke(...)
    

    instead of lbl.Invoke(.... I had to do this. This is my implementation:

    Delegate Sub SetTextDelegate(ByVal args As String)
    
    Private Sub SetTextBoxInfo(ByVal txt As String)
        If txtInfo.InvokeRequired Then
            Dim md As New SetTextDelegate(AddressOf SetTextBoxInfo)
            Me.Invoke(md, txt)
        Else
            txtInfo.Text = txt
        End If
    End Sub
    

    And this worked for me.

提交回复
热议问题