Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Invoke Webbrowser from a seperate thread vb.net

Avatar of kanus
kanus asked on
Visual Basic.NET
21 Comments1 Solution1965 ViewsLast Modified:
Hi all,

I've spent a couple hours trying to figure out threading and how to access form controls from a separate thread but I'm still confused. Any help would be appreciated. Here is some simplified code to give you an example of what I'm trying to do:

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        Dim newThread As Thread = New Thread(AddressOf Timer2_Work)
    End Sub

    Private Sub Timer2_Work()
                    Dim val As String = "somevalue"
                    Dim element As String = "TheNameOfSomeWebPageElement"
                    WebBrowser1.Document.All(element).InnerText = val
    End Sub

This code gives me the error "Specified cast is not valid." and I have to assume the error is threading related, and the webbrowser control has to be called from the thread its on.

I've tried several things, and tried replicating some examples I've found, but never actually got it working. If you can provide a example of how I could accomplish this, or direct me to a "vb.net threading for complete idiots" page, I would be very grateful.
Avatar of MikeQc
MikeQcFlag of Canada image

Our community of experts have been thoroughly vetted for their expertise and industry experience.

This problem has been solved!
Unlock 1 Answer and 21 Comments.
See Answers