locked
making a program wait until webbrowser finish loading c# RRS feed

  • Question

  • I want to make my program wait until I’ve finished loading the webbrowser page after it
    finished loading <o:p></o:p>

    I’m calling the WebBrowserDocumentCompletedEventHandler and getting a value i need from the webpage and then i want to resume the program<o:p></o:p>

    I’ve tried using a loop checking the state and also AutoResetEvent
    but it doesn’t work and the
    WebBrowserDocumentCompletedEventHandler never fires<o:p></o:p>

    Plz Help?

    Monday, October 8, 2012 12:09 AM

Answers

  • Ive Tried using this

    while (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
       
    Application.DoEvents();

    but for some reasing the Readystate never changes to Complete

    • Marked as answer by RoeyMoyal Friday, October 19, 2012 1:45 AM
    Monday, October 8, 2012 7:29 AM

All replies

  • You don't call WebBrowserDocumentCompletedEventHandler, but rather you create a handler which is called when navigation complets.
     

    --
    Mike
    Monday, October 8, 2012 12:22 AM
  • Yes I know

    if i dont try to stop the program it fires

    if it helps this is my code basically

    private void WebBrowser_DocumentCompleted_GotoShow(object sender, WebBrowserDocumentCompletedEventArgs e)

    {

       // Get something from the website        

    }

    public void GetShow(string Show)

    {

       this.DocumentCompleted -= new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(this.WebBrowser_DocumentCompleted_CheckingLogin);

       this.DocumentCompleted += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(this.WebBrowser_DocumentCompleted_GotoShow);

       this.GetShowNumberLink = this.Link + Show + "/";

       this.Navigate(this.GetShowNumberLink);

       // Wait here until document complete 

    }

    After calling the Navigate func I want the program to wait until I've finished handling the WebBrowserDocumentCompletedEvent<o:p></o:p>


    Monday, October 8, 2012 12:32 AM
  • I guess I am at a loss for what you want.  Your code won't do anything until the document completed fires.
     
    Is it possible that you want to do something in GetShow() after your handler code?  If so, move that code to the handler.

    --
    Mike
    Monday, October 8, 2012 12:43 AM
  • The problem is that if i want stop after

    this.Navigate(this.GetShowNumberLink);

    my program will continue and i need the data from the site to continue in the program

    Monday, October 8, 2012 12:50 AM
  • OK, as I said, put the code which needs the data from the site into the routine "WebBrowser_DocumentCompleted_GotoShow".

    --
    Mike
    Monday, October 8, 2012 12:57 AM
  • Use this pattern:

          webBrowser1.Navigate(textBox1.Text);
        }
        private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
          if (webBrowser1.Url == e.Url)
          {
            if (webBrowser1.ReadyState == WebBrowserReadyState.Complete)
            {
              //Do Stuff
    

    Monday, October 8, 2012 1:47 AM
  • You could try:

    while (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
        Application.DoEvents();

    I've seen that in samples on the web.  Not sure if there should be some kind of wait in there or not.

    Monday, October 8, 2012 2:49 AM
  • Ive Tried using this

    while (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
       
    Application.DoEvents();

    but for some reasing the Readystate never changes to Complete

    • Marked as answer by RoeyMoyal Friday, October 19, 2012 1:45 AM
    Monday, October 8, 2012 7:29 AM
  • I am facing same issue as like you. Did you get the solution?

    If yes then please share the solution.

    Thursday, January 23, 2014 4:16 AM