Results 1 to 3 of 3

Thread: create hidden web browser control

  1. #1
    ninjaimp is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 2.0
    Join Date
    Jun 2007
    Posts
    80
    Reputation
    76

    Exclamation create hidden web browser control

    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:

    Code:
        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

  2. #2
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,197
    Reputation
    2368
    Thread.Sleep(5000)
    This makes your thread stop completely for 5 seconds, absolutely nothing will happen in the thread during this time. Try this:
    Code:
    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.

  3. #3
    ninjaimp is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 2.0
    Join Date
    Jun 2007
    Posts
    80
    Reputation
    76
    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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking