Results 1 to 12 of 12

Thread: [RESOLVED] Waiting for a webpage to load?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Posts
    27

    Resolved [RESOLVED] Waiting for a webpage to load?

    Hello!
    I have a problem with timers starting before a document finished downloading on a webbrowser.

    Thake this as a example:
    sub something()
    wbBrowser.Refresh
    tTimer.Start
    end sub

    The webbrowser starts refreshing and the timer starts instantly.
    What i need is to wait until the document has loaded for the timer to start.
    But its not as easy as moving the tTimer.Start to the wbBrowser.DocumentCompleted event, because i need this only on that refresh instance.
    I mean only to happen like that when the refresh method is called from inside the sub something.

    Did i make my self clear?
    Because its a bit hard to explain lol

    Well, thanks in advance.
    Last edited by juanchoc; Dec 5th, 2005 at 12:27 AM.

  2. #2

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Posts
    27

    Re: Wait for a DocumentCompleted Event?

    Well i tryed this now:

    sub something()
    wbBrowser.Refresh

    Do While wbBrowser.IsBusy = True
    Application.DoEvents()
    Loop

    tTimer.Start
    end sub

    But with no sucsess.

  3. #3
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Wait for a DocumentCompleted Event?

    Are you setting IsBusy to False in the Document Complete event?

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Posts
    27

    Re: Wait for a DocumentCompleted Event?

    Hmm no.
    Should i?

    Sory im kinda new to vb

    Btw, IsBusy is readonly, how am i supposed to set it to false?

  5. #5
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Wait for a DocumentCompleted Event?

    Well, this is from VB6, but you could create your own variable, and after calllng the document, set the value.

    VB Code:
    1. blnBusy = True
    2. Do While blnBusy = True
    3. Loop

    And then set it to false in the Complete event.

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Posts
    27

    Re: Wait for a DocumentCompleted Event?

    But the problem is that if i use the DocumentCompleted, ill be waiting for all the webpages displayed on my program to be completed.
    And what i need i that just on that request, thats been made on that sub.
    Got it?

    Thats why i thought maybe if i make the program go in a do while loop while the browser is busy, it should "wait" until its idle to continue with my code.

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Posts
    27

    Re: Wait for a DocumentCompleted Event?

    Isnt there any way of stoping code execution until one exact page finished loading?
    I mean i can use the DocumentCompleted method but that will afect all of the webpage loading that apears thou all my program, and i just need this to happen on only one sub and anywhere else of my code.

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Posts
    27

    Re: Wait for a DocumentCompleted Event?

    Hmm sory for the posting number lol

    Here is the code so its easyer to understand what i mean:

    Code:
        Private Sub tTimer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tTimer.Tick
            tTimer.Stop()
            tClock.Stop()
    
            wbAutoBrowser.ScriptErrorsSuppressed = True
    
            If Refreshed = True Then
                DeparseUrls()
                Refreshed = False
            End If
    
            If j >= 0 Then
                wbAutoBrowser.Navigate(Url & results(j))
                j = j - 1
                tTimer.Interval = ClickWaitInterval
            ElseIf j < 0 Then
                tTimer.Interval = BrowserRefreshInterval
                wbBrowser.Refresh()
                Refreshed = True
            End If
    
            Do While wbAutoBrowser.IsBusy = True
                Application.DoEvents()
            Loop
    
            Do While wbBrowser.IsBusy = True
                Application.DoEvents()
            Loop
    
            dStart = DateTime.Now
    
            tTimer.Start()
            tClock.Start()
        End Sub
    As you can see i tryed to make the application enter the do while loop until the browser is idle, and the continue and start the timers.
    But for some strange reason it never enters none of the do while loops!
    In theory this would solve my problem, but for some reason it just doesnt work.
    So if someone helps me make it work ill be really thankful

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Posts
    27

    Re: Waiting for a webpage to load?

    Well, now i tryed two other thing, but with no succsess...

    Code:
            Do Until wbAutoBrowser.ReadyState <> WebBrowserReadyState.Complete
                Application.DoEvents()
            Loop
    
            Do Until wbBrowser.ReadyState <> WebBrowserReadyState.Complete
                Application.DoEvents()
            Loop
    Code:
            Do While wbAutoBrowser.ReadyState <> WebBrowserReadyState.Complete
                Application.DoEvents()
            Loop
    
            Do While wbBrowser.ReadyState <> WebBrowserReadyState.Complete
                Application.DoEvents()
            Loop
    Any sugestions?

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Posts
    27

    Re: Waiting for a webpage to load?

    Well after furter research about the ReadyState property, i tryed this:

    Code:
            Do Until (wbAutoBrowser.ReadyState = 4) Or (wbAutoBrowser.ReadyState = 0)
                Application.DoEvents()
            Loop
    
            Do Until (wbBrowser.ReadyState = 4) Or (wbBrowser.ReadyState = 0)
                Application.DoEvents()
            Loop
    And this:

    Code:
            Do Until (wbAutoBrowser.ReadyState.ToString = "Complete") Or (wbAutoBrowser.ToString = "Uninitialized")
                Application.DoEvents()
            Loop
    
            Do Until (wbBrowser.ToString = "Complete") Or (wbBrowser.ToString = "Uninitialized")
                Application.DoEvents()
            Loop
    But neither of those two are working...
    This is really starting to piss me off lol
    I dont see what im doing wrong, can someone point me in the right direction please?

    Thanks in advance,
    JCC

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Posts
    27

    Talking Re: Waiting for a webpage to load?

    Wow finally solved!
    Well after trying a lot of things i got an idea that worked like a charm!

    Instead of using the DocumentCompleted method, that wasnt working to me, Im using the ProgressChanged method and i add a If and a boolean. Like this:

    Code:
    If e.MaximumProgress = e.CurrentProgress Then
                AutoBrowserComplete = True
            End If
    And this on the other sub:

    Code:
    Do While BrowserComplete = False
                Application.DoEvents()
            Loop
    Please Congratulate me! lol
    This was a hard one, and theres no mention of doing it like this on any other site

  12. #12
    New Member
    Join Date
    May 2002
    Posts
    5

    Re: [RESOLVED] Waiting for a webpage to load?

    I know this is an old post, but anyone who finds this could also try:

    VB Code:
    1. Do Until WebBrowser1.ReadyState = WebBrowserReadyState.Complete
    2.             Application.DoEvents()
    3.         Loop

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