locked
Threading Issue RRS feed

  • Question

  • Hi,

    Im having a threading issue but unsure where it is happening in my code since the stack trace doesnt tell me where nor does iexplore.

    System.NullReferenceException was unhandled
    Message="Object reference not set to an instance of an object."Source="System.Windows.Forms"
    StackTrace:
           at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous)
           at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args)
           at System.Windows.Forms.Control.Invoke(Delegate method)
           at yWorks.Canvas.Animation.Animator.b()
           at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           at System.Threading.ExecutionContext.runTryCode(Object userData)
           at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
           at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart()

    Any ideas what this means?, other than something is null.

    Regards,
    Gareth.
    Thursday, February 8, 2007 11:38 AM

Answers

  • Hi Gareth

    It seems that the destination object on your cross thread invoke is null, check the methos that you are delegating, if is not null or the method that refers exists. you must put a breakpoint on the delegated method to see what is going on.

    Best regards

    Thursday, February 8, 2007 1:07 PM

All replies

  • Hi Gareth

    It seems that the destination object on your cross thread invoke is null, check the methos that you are delegating, if is not null or the method that refers exists. you must put a breakpoint on the delegated method to see what is going on.

    Best regards

    Thursday, February 8, 2007 1:07 PM
  • I've been having the same problem but I think I finally worked out what was going on:

            public delegate void ShowImportCallback();

            public void ShowImport()
            {

                // m_main is a wodows control
                if (this.m_main.InvokeRequired)
                {
                    ShowImportCallback d = new ShowImportCallback(ShowImport);
                    m_main.Invoke(d);  // The debugger reports the error against this line - not against the faulty code!
                }
                else
                {
                     // Code here to update m_main - but with a NullRefernce error

                    doSomthingThatRaisesNullRefernceException() ;

                   }
            }

    So I've spent half a day trying to find out what was wrong with my call to Invoke() when the problem is really in the code that runs when Invoke() is called.

    Jackson

    Thursday, March 15, 2007 10:49 AM
  • The same delegation approach with Control.InvokeRequired is not working for me.

    Code Block

    Public Delegate Sub setFormTopDelegate(ByVal value As Integer)

    Public Sub SetFormTop(ByVal value As Integer)
        If Me.InvokeRequired Then
            Dim d As New setFormTopDelegate(AddressOf SetFormTop)
            'Me.Invoke(New setFormTopDelegate(AddressOf SetFormTop), value)  'Throws NullReferenceException.
            Me.Invoke(d, value)    'Throws the same exception! d = setFormTopDelegate, value = 150. No invalid references at runtime. Even "Me" exists.
        Else
            Debug.Writeline ("InvokeRequired = False")    'Breakpointed but doesnt hit. Doesnt show anything in the Immediate Window as well.
            'Me.Top = value    ' Commented this line and added the above line to check whether the code in this section has problems.
        End If
    End Sub



    The above code doesnt work for me. Throws the same conspicuous NullReferenceException : Oject reference not set to an instance of an object.

    I tried setting a breakpoint on the Invoke line and check for valid references, but I couldnt find any invalid references.

    I've been searching for a solution, but it is still eluding me. Any guiding light (even at the end of the tunnel) will be helpful.



    Peace !
    Gary
    Saturday, December 1, 2007 4:04 PM