Question create hidden web browser control

ninjaimp

Well-known member
Joined
Jun 13, 2007
Messages
80
Programming Experience
1-3
Hi

Im tryingto create/run a webbrowser control so that i can check the status. I dont need to see the page so havent placed the webbrowser control on a form - its just in code as follows:

VB.NET:
    Sub TestBrowse(ByVal url As String)

        Dim testbrowse As New WebBrowser

        testbrowse.Navigate(url)

        System.Threading.Thread.Sleep(5000)

        MsgBox("Status - " & testbrowse.ReadyState.ToString)


    End Sub

the problem is that it never initialises and is always at the state 'Uninitialized'

do i have to do something to the control to get it to run, or does it have to be physically on a form before i can use a web browse control

regards
 
Thread.Sleep(5000)
This makes your thread stop completely for 5 seconds, absolutely nothing will happen in the thread during this time. Try this:
VB.NET:
Do Until testbrowse.ReadyState = WebBrowserReadyState.Complete
    Application.DoEvents()
Loop
'document loaded
If the loading may take some time it is better to use the Navigated or DocumentCompleted event, use AddHandler statement to add event handler dynamically if you're creating multiple instances in code.
 
many thanks for this John, I'll look into this now!

So is it ok to use a web browser control in the way i have?

Edit:
that solved it john - many thanks for your help
 
Back
Top