Stack Trace of cross-thread exceptions with Invoke

Posted by the_lotus on Stack Overflow See other posts from Stack Overflow or by the_lotus
Published on 2010-03-30T15:37:09Z Indexed on 2010/03/30 15:43 UTC
Read the original article Hit count: 359

Filed under:
|
|

When an exception happens after calling Invoke, .NET shows the stack trace as if the error happens while calling Invoke.

Example below: .NET will say the error happen in UpdateStuff instead of UpdateStuff -> BadFunction

Is there a way to catch the "real" exception and show the correct stack trace?

Private Sub UpdateStuff()

    If (Me.InvokeRequired) Then
        Me.Invoke(New UpdateStuffDelegate(AddressOf UpdateStuff))
        Return
    End If

    Badfunction()

End Sub

Private Sub BadFunction()

    Dim o As Object

    o.ToString()

End Sub

© Stack Overflow or respective owner

Related posts about .NET

Related posts about multithreading