• Welcome to Valhalla Legends Archive.
 

[VB.Net] TargetParameterCountException

Started by Imperceptus, March 05, 2008, 01:01 PM

Previous topic - Next topic

Imperceptus

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?

Quote from: Hazard on August 07, 2003, 03:15 PM
Highlight your entire code. Press the delete key. Start over again using Cuphead's CSB tutorial and work your way from their rather than raping code from downloaded sources meant purely for learning purposes. If this does not fix the problem, uninstall Visual Basic and get a new hobby. I suggest Cricket.

Imperceptus

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.
Quote from: Hazard on August 07, 2003, 03:15 PM
Highlight your entire code. Press the delete key. Start over again using Cuphead's CSB tutorial and work your way from their rather than raping code from downloaded sources meant purely for learning purposes. If this does not fix the problem, uninstall Visual Basic and get a new hobby. I suggest Cricket.

MyndFyre

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.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.