ISynchronizeInvoke.Invoke call

T

Thai Mai Shu

What is wrong with my call below. If I change the
delegate and the CallBackComplete function to not take in
parameters then the .Invoke call works fine. As soon as I
put the parameters back I get "Parameter count mismatch."
error. Am I supposed to implement ISynchronizeInvoke in
order to call .Invoke? If so, why does it work when the
method i am trying to invoke has no parameters.

Private Delegate Sub CallbackCompleteDelegate(ByVal args()
As Object)

Private Sub SomeCallback(ByVal ACResult As IAsyncResult)
' calls .EndInvoke and does some async work

Dim Test As New CallbackCompleteDelegate(AddressOf
CallbackComplete)

Dim args(1) As Object
args(0) = "one"
args(1) = "two"

MainForm.Invoke(Test, args)
End Sub

Private Sub CallbackComplete(ByVal args() As Object)
' not even accessing the parameters

Debug.WriteLine("CallbackComplete - " &
AppDomain.GetCurrentThreadId)
End Sub
 
G

Guest

Your delegate and CallbackComplete need to list out the
parameters and not take them in as an array. So...

Private Delegate Sub CallbackCompleteDelegate(ByVal one As
Object, ByVal two As Object)

Private Sub SomeCallback(ByVal ACResult As IAsyncResult)
' calls .EndInvoke and does some async work

Dim Test As New CallbackCompleteDelegate(AddressOf
CallbackComplete)

Dim args(1) As Object
args(0) = "one"
args(1) = "two"

MainForm.Invoke(Test, args)
End Sub

Private Sub CallbackComplete(ByVal one As Object, _
ByVal two As Object)
' not even accessing the parameters

Debug.WriteLine("CallbackComplete - " &
AppDomain.GetCurrentThreadId)
End Sub
 

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