Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. C# Form Application - WebBrowserControl - DocumentComplete issue

C# Form Application - WebBrowserControl - DocumentComplete issue

Scheduled Pinned Locked Moved C#
helpquestioncsharpdebuggingsales
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jon Braunsma
    wrote on last edited by
    #1

    I have a C# 3.5 Windows form application that uses the webbrowser control. This control is used to navigate through a website, where I have a parsing engine that pulls data off the site and stores it in a file. The customer navigates to the site, presses the "record" button and the parsting starts. The parser is triggered by the DocumentComplete event. This works very well, but I have seen that this event sometimes does not fire. The customer has to navigate through 500 pages and by the time they get to page 500, we found that we are missing maybe 5-6 of the pages. We have traced the problem to be that the documentcomplete event is not firing all the time. My debug code indicates that the navigating and havigated events have fired correctly, but not the document complete. At the end of the 500 page run, I have 500 navigating events, 500 navigated events and a variable number of documentcompelte events, ranging from 490-495. We have not traced it to any single page, but are unable to figure out what is causing this. We even added a sound that beeps when the page loads and have found pages that load in the browser and are viewable, but the sound does not play because the event didn't fire. Any thoughts what might be causing this?

    D realJSOPR L J 4 Replies Last reply
    0
    • J Jon Braunsma

      I have a C# 3.5 Windows form application that uses the webbrowser control. This control is used to navigate through a website, where I have a parsing engine that pulls data off the site and stores it in a file. The customer navigates to the site, presses the "record" button and the parsting starts. The parser is triggered by the DocumentComplete event. This works very well, but I have seen that this event sometimes does not fire. The customer has to navigate through 500 pages and by the time they get to page 500, we found that we are missing maybe 5-6 of the pages. We have traced the problem to be that the documentcomplete event is not firing all the time. My debug code indicates that the navigating and havigated events have fired correctly, but not the document complete. At the end of the 500 page run, I have 500 navigating events, 500 navigated events and a variable number of documentcompelte events, ranging from 490-495. We have not traced it to any single page, but are unable to figure out what is causing this. We even added a sound that beeps when the page loads and have found pages that load in the browser and are viewable, but the sound does not play because the event didn't fire. Any thoughts what might be causing this?

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      It could very easily be the server that caused the problem. It's not guaranteed that you will get a DocumentCompleted for every nagivation. You're only recourse is to put a timer in there and if the page does not complete within, say 1 minute, retry the navigation.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007, 2008
      But no longer in 2009...

      J 1 Reply Last reply
      0
      • J Jon Braunsma

        I have a C# 3.5 Windows form application that uses the webbrowser control. This control is used to navigate through a website, where I have a parsing engine that pulls data off the site and stores it in a file. The customer navigates to the site, presses the "record" button and the parsting starts. The parser is triggered by the DocumentComplete event. This works very well, but I have seen that this event sometimes does not fire. The customer has to navigate through 500 pages and by the time they get to page 500, we found that we are missing maybe 5-6 of the pages. We have traced the problem to be that the documentcomplete event is not firing all the time. My debug code indicates that the navigating and havigated events have fired correctly, but not the document complete. At the end of the 500 page run, I have 500 navigating events, 500 navigated events and a variable number of documentcompelte events, ranging from 490-495. We have not traced it to any single page, but are unable to figure out what is causing this. We even added a sound that beeps when the page loads and have found pages that load in the browser and are viewable, but the sound does not play because the event didn't fire. Any thoughts what might be causing this?

        realJSOPR Offline
        realJSOPR Offline
        realJSOP
        wrote on last edited by
        #3

        You could always fire your own event when you get a response back from the server.

        .45 ACP - because shooting twice is just silly
        -----
        "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
        -----
        "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

        1 Reply Last reply
        0
        • J Jon Braunsma

          I have a C# 3.5 Windows form application that uses the webbrowser control. This control is used to navigate through a website, where I have a parsing engine that pulls data off the site and stores it in a file. The customer navigates to the site, presses the "record" button and the parsting starts. The parser is triggered by the DocumentComplete event. This works very well, but I have seen that this event sometimes does not fire. The customer has to navigate through 500 pages and by the time they get to page 500, we found that we are missing maybe 5-6 of the pages. We have traced the problem to be that the documentcomplete event is not firing all the time. My debug code indicates that the navigating and havigated events have fired correctly, but not the document complete. At the end of the 500 page run, I have 500 navigating events, 500 navigated events and a variable number of documentcompelte events, ranging from 490-495. We have not traced it to any single page, but are unable to figure out what is causing this. We even added a sound that beeps when the page loads and have found pages that load in the browser and are viewable, but the sound does not play because the event didn't fire. Any thoughts what might be causing this?

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          For debugging purposes, you could try the following: 1. get the target URL from the Navigating event; 2. cancel the Navigation; 3. use your own code to fetch the page text, using HttpWebRequest and HttpWebResponse; 4. when the response is in, stuff the result into WebBrowser.DocumentText You can now add logging/debugging stuff to step 3 until you discover what is going on; then work from there. BTW: I am not suggesting you do this as the final solution! A timeout/retry scheme seems fine, the one problem with it is you'll never know what exactly is going wrong. :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


          I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.


          J 1 Reply Last reply
          0
          • D Dave Kreskowiak

            It could very easily be the server that caused the problem. It's not guaranteed that you will get a DocumentCompleted for every nagivation. You're only recourse is to put a timer in there and if the page does not complete within, say 1 minute, retry the navigation.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007, 2008
            But no longer in 2009...

            J Offline
            J Offline
            Jon Braunsma
            wrote on last edited by
            #5

            Dave, Thank you for the reply. Your recommendation makes sense. However, I was unaware that I am not guaranteed a DocumentCompleted event for each successful navigation. What would couse the DocumentCompelted not to fire? The strange thing is, I can see the page in the browser and I can interact with it, so the page has loaded (or so it seems), but again no DocumentCompleted event. Can you elaborate on when I can expect the event to fire and when not to? thanks for the reply. Jon

            D 1 Reply Last reply
            0
            • L Luc Pattyn

              For debugging purposes, you could try the following: 1. get the target URL from the Navigating event; 2. cancel the Navigation; 3. use your own code to fetch the page text, using HttpWebRequest and HttpWebResponse; 4. when the response is in, stuff the result into WebBrowser.DocumentText You can now add logging/debugging stuff to step 3 until you discover what is going on; then work from there. BTW: I am not suggesting you do this as the final solution! A timeout/retry scheme seems fine, the one problem with it is you'll never know what exactly is going wrong. :)

              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


              I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.


              J Offline
              J Offline
              Jon Braunsma
              wrote on last edited by
              #6

              I like the idea of digging in to this deeper. I need to figure out what is causing this event not to fire and this seems like a very good way to help isolate it. Thank you.

              1 Reply Last reply
              0
              • J Jon Braunsma

                Dave, Thank you for the reply. Your recommendation makes sense. However, I was unaware that I am not guaranteed a DocumentCompleted event for each successful navigation. What would couse the DocumentCompelted not to fire? The strange thing is, I can see the page in the browser and I can interact with it, so the page has loaded (or so it seems), but again no DocumentCompleted event. Can you elaborate on when I can expect the event to fire and when not to? thanks for the reply. Jon

                D Offline
                D Offline
                Dave Kreskowiak
                wrote on last edited by
                #7

                Jon Braunsma wrote:

                What would couse the DocumentCompelted not to fire?

                The server not sending a complete document or a missing HTML closing tag.

                A guide to posting questions on CodeProject[^]
                Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                     2006, 2007, 2008
                But no longer in 2009...

                1 Reply Last reply
                0
                • J Jon Braunsma

                  I have a C# 3.5 Windows form application that uses the webbrowser control. This control is used to navigate through a website, where I have a parsing engine that pulls data off the site and stores it in a file. The customer navigates to the site, presses the "record" button and the parsting starts. The parser is triggered by the DocumentComplete event. This works very well, but I have seen that this event sometimes does not fire. The customer has to navigate through 500 pages and by the time they get to page 500, we found that we are missing maybe 5-6 of the pages. We have traced the problem to be that the documentcomplete event is not firing all the time. My debug code indicates that the navigating and havigated events have fired correctly, but not the document complete. At the end of the 500 page run, I have 500 navigating events, 500 navigated events and a variable number of documentcompelte events, ranging from 490-495. We have not traced it to any single page, but are unable to figure out what is causing this. We even added a sound that beeps when the page loads and have found pages that load in the browser and are viewable, but the sound does not play because the event didn't fire. Any thoughts what might be causing this?

                  J Offline
                  J Offline
                  Jon Braunsma
                  wrote on last edited by
                  #8

                  Thank you all for the input. By using a combination of solutions recommended, I was able to detect the condition. After the navigated event fires, I set a timer and if the documentcomplete event does not fire in the specified time, I can immediately detect the issue and alert the user. This is an acceptible work around for now. I will dig more in to the issue later. Thank you all for the advice.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups