Results 1 to 7 of 7

Thread: Question about what happens when I navigate form1.webrowser1 from non UI thread

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2013
    Location
    Overland Park Kansas
    Posts
    183

    Question about what happens when I navigate form1.webrowser1 from non UI thread

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim navthread1 As New System.Threading.Thread(AddressOf Module1.navigate)
           
            navthread1.Start("www.yahoo.com")
    
            System.Threading.Thread.Sleep(1)
    
    
        End Sub
    
    
    
    Public Delegate Sub navigatecallback(ByVal site As String)
        Public Sub navigate(ByVal site As String)
            Dim main As Form1 = CType(System.Windows.Forms.Application.OpenForms(0), Form1)
    
            If main.WebBrowser1.InvokeRequired Then
                main.WebBrowser1.Invoke(New navigatecallback(AddressOf navigate), site)
    
            Else
    
                main.WebBrowser1.Navigate(site)
            End If
        End Sub

    When I step through it runs like there is no multithreading at all. module1.navigate does not even start until after the buttonclick event sub has ended. What is the difference between this code that i've posted and doing this?:

    (other than this bottom code navigates the webbrowser BEFORE the button click sub has ended)

    Am I doin something wrong with my navthread1 which prevents it from doing anything until after the button1 click sub has ended?

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        form1.webbrowser1.navigate("www.yahoo.com")
        End Sub

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Question about what happens when I navigate form1.webrowser1 from non UI thread

    WebBrowser navigation is asynchronous already (just the navigation, mind, before all the naysayers pitch in!) so effectively you're starting a thread and invoking a callback to the UI thread to start yet another thread to do the navigation. If navigating is all you want to do then none of it is taking place in the thread that you have here.

    I said a long time ago that the way to handle checking that a website was loaded if the program was otherwise not dependent on it was to start a timer to check when the particular element of interest was available and either process it or raise an alert or event at that time and then stop.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2013
    Location
    Overland Park Kansas
    Posts
    183

    Re: Question about what happens when I navigate form1.webrowser1 from non UI thread

    Quote Originally Posted by dunfiddlin View Post
    I said a long time ago that the way to handle checking that a website was loaded if the program was otherwise not dependent on it was to start a timer to check when the particular element of interest was available and either process it or raise an alert or event at that time and then stop.
    So how would I handle this:

    I navigate to a website, the document is completed, but the macros are not completed? The document completed event says DOCUMENT COMPLETED! But there is no macro completed event... When the document is completed but macros are not completed the HTML elements are the same as when the document is completed and the macros are completed.

    What needs to happen for me to get the navigation of the webbrowser off of the UI thread?

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Question about what happens when I navigate form1.webrowser1 from non UI thread

    What macros?

    And you can't really get it off the UI thread because it inherently is updating the UI... so it's going to be on the UI thread by its very nature.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    Re: Question about what happens when I navigate form1.webrowser1 from non UI thread

    You may want to look into the WebRequest. A WebBrowser control is intended to show a web page to the user, which is why it is inherently UI. If you don't care whether the user sees anything or not, then a WebBrowser may not be what you want to use.
    My usual boring signature: Nothing

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jan 2013
    Location
    Overland Park Kansas
    Posts
    183

    Re: Question about what happens when I navigate form1.webrowser1 from non UI thread

    Quote Originally Posted by techgnome View Post
    What macros?

    And you can't really get it off the UI thread because it inherently is updating the UI... so it's going to be on the UI thread by its very nature.

    -tg
    The webpage HTML included an object and the object created in the website's HTML runs a macro which logs into the server created by the object. The macro happens after the document completed event. so for it to work i'd have to have some sort of wait function on the document completed event that waits for a half second for the document's objects to run it's macros.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jan 2013
    Location
    Overland Park Kansas
    Posts
    183

    Re: Question about what happens when I navigate form1.webrowser1 from non UI thread

    Quote Originally Posted by Shaggy Hiker View Post
    You may want to look into the WebRequest. A WebBrowser control is intended to show a web page to the user, which is why it is inherently UI. If you don't care whether the user sees anything or not, then a WebBrowser may not be what you want to use.
    I will look into this now! Thanks for the ideas!

Posting Permissions

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



Click Here to Expand Forum to Full Width