Click here to Skip to main content
15,916,945 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've been trying to figure out how to add another variable to "my" delegate
for my callback function - but after hours of searching the net I have not been able to understand how it's done :-(

So here is my question:
How to I expand the code below to add another variable (I can do that In the delegate statement [public delegate sub SetText...]without problems but then i can not pass it to the delegate when I create it[Dim d as new SetText...] ???)

Thanks for any inputs :)

Delegate Sub SetTextCallback(ByVal [text] As String)

   Public Sub SetPRGMessageText(ByVal [text] As String)
       ' InvokeRequired required compares the thread ID
       ' If the creator thread of the control is different then the caller Thread
       ' this Sub will be called by cretor thread of the control
       If MenuStrip_Main.InvokeRequired Then
           Dim d As New SetTextCallback(AddressOf SetPRGMessageText) ' this is the call back to [SetPRGMessageText]using the creator
           Me.Invoke(d, New Object() {[text]})
           Me.ToolStripTxB_Message.Text = [text]
       End If
   End Sub
Henry Minute 11-Jun-10 13:52pm    
Do you always want the extra parameter, or just sometimes?

1 solution

You should just be passing the additional parameter into the invoke after you're done adding it to your signature.

So, this:

Me.Invoke(d, New Object() {[text]})

Me.Invoke(d, New Object() {[text], [text2]})

Something like that.



Here's a snippet that would work, with either syntax you can call invoke...

Public Class Form1

    Delegate Sub SetTextCallback(ByVal A As String, ByVal B As String)

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim d As New SetTextCallback(AddressOf Method)

        Invoke(d, "A", "B")
        Invoke(d, New Object() {"One", "Two"})
    End Sub

    Private Sub Method(ByVal A As String, ByVal B As String)
        Trace.Write(String.Format("{0} {1}", A, B))
    End Sub
End Class
Share this answer
Georg Kohler 11-Jun-10 18:08pm    
THIS WORKED !!!!!!!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900