I was running into a cross-threading error. I had hoped that using delegates would solve the issue. but instead I have a different error now.
Public Sub AddChat(ByVal ParamArray obj() As Object)
Dim callback As New AddChatCallback(AddressOf AddChatImpl)
If Me.InvokeRequired Then
Me.Invoke(callback, obj)
Else
callback(obj)
End If
End Sub
Data is recieved in mysocket.vb class
Event Is raised which is picked up by a form which is a child of an mdi form.
that form calls addchat in my rtb class.
I get a TargetParameterCountException when it gets to Me.Invoke in the If statement. Obj does have data. Any idea's?
I made the code changes
Public Sub AddChat(ByVal ParamArray obj() As Object)
Dim callback As New AddChatCallback(AddressOf AddChatImpl)
If Me.InvokeRequired Then
Me.Invoke(callback, obj.syncroot)
Else
callback(obj)
End If
End Sub
This seems to have fixed my problem. Any other comments would be appreciated.
Calling Invoke() on a ParamArray method is tricky. Using SyncRoot isn't really what you want to do -- it's not intended for use that way.
Is AddChatImpl's parameter a ParamArray? You can just change it to a regular array.