VB.NET 2.0 - StackOverflowException when using Thread Safe calls to Windows Forms Controls

Posted by LamdaComplex on Stack Overflow See other posts from Stack Overflow or by LamdaComplex
Published on 2011-09-22T13:00:14Z Indexed on 2012/06/02 4:40 UTC
Read the original article Hit count: 228

I have a Windows Forms app that, unfortunately, must make calls to controls from a second thread. I've been using the thread-safe pattern described on the http://msdn.microsoft.com/en-us/library/ms171728.aspx. Which has worked great in the past.

The specific problem I am having now: I have a WebBrowser control and I'm attempting to invoke the WebBrowser.Navigate() method using this Thread-Safe pattern and as a result I am getting StackOverflow exceptions. Here is the Thread-Safe Navigate method I've written.

Private Delegate Sub NavigateControlCallback(ByRef wb As WebBrowser, ByVal url As String)

Private Sub AsyncNavigate(ByRef wb As WebBrowser, ByVal URL As String)
    Try
        If wb.InvokeRequired Then
            Dim callback As New NavigateControlCallback(AddressOf AsyncNavigate)
            callback(wb, url)
        Else
            wb.Navigate(url)
        End If
    Catch ex As Exception

    End Try
End Sub

Is there a Thread-Safe way to interact with WinForms components without the side effect of these StackOverflowExceptions?

© Stack Overflow or respective owner

Related posts about vb.net

Related posts about winforms