Home All Groups Group Topic Archive Search About

Parameter count mismatch??? passing an array to Invoke

Author
14 Jun 2006 12:05 AM
andrewbb
This is fairly simple code, what am I missing or is there a potential
workaround?

It fails when passing someParms to Invoke with "Parameter count
mismatch".  I created a test with an empty form and a single button.
Thanks in advance.

By the way, in case you're wondering why... I want to call into the
form from a different thread to update controls.


Private Delegate Sub MyDelegate(ByVal parm() As Object)

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

        Dim myDel As MyDelegate
        myDel = New MyDelegate(AddressOf AProcedure)

        Dim someParms(2) As Object
        someParms(0) = "abc"
        someParms(1) = "def"

        myDel.Invoke(someParms)    'WORKS!

        Invoke(myDel, someParms) ' doesn't work :(
End Sub

Private Sub AProcedure(ByVal parm() As Object)
        MessageBox.Show(parm.Length)
End Sub

Author
14 Jun 2006 5:59 AM
Mattias Sjögren
>        Dim someParms(2) As Object

Should be someParms(1) if you only have two parameters.


>        Invoke(myDel, someParms) ' doesn't work :(

Try

Invoke(myDel, New Object() {someParms})


Mattias

--
Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Author
14 Jun 2006 4:59 PM
andrewbb
Yes, thank you!

Mattias Sjögren wrote:
Show quoteHide quote
> >        Dim someParms(2) As Object
>
> Should be someParms(1) if you only have two parameters.
>
>
> >        Invoke(myDel, someParms) ' doesn't work :(
>
> Try
>
> Invoke(myDel, New Object() {someParms})
>
>
> Mattias
>
> --
> Mattias Sjögren [C# MVP]  mattias @ mvps.org
> http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
> Please reply only to the newsgroup.