Parameter count mismatch??? passing an array to Invoke

A

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
 
M

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top