Multi-threading and delegates

MikePehlvan

New member
Joined
Mar 30, 2008
Messages
1
Programming Experience
3-5
how can i create a delegate sub whereby i pass it a label and text and it goes and changes that label's text property on any form/class?

and how can i call this sub properly?
 
Snippet from How to: Make Thread-Safe Calls to Windows Forms Controls :
VB.NET:
Delegate Sub SetTextCallback([text] As String)

Private Sub SetText(ByVal [text] As String)

    ' InvokeRequired required compares the thread ID of the
    ' calling thread to the thread ID of the creating thread.
    ' If these threads are different, it returns true.
    If Me.textBox1.InvokeRequired Then
        Dim d As New SetTextCallback(AddressOf SetText)
        Me.Invoke(d, New Object() {[text]})
    Else
        Me.textBox1.Text = [text]
    End If
End Sub
You can modify sub to take any parameter.
 
Back
Top