Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Assuming you host <code>WebBrowser</code> in a WinFroms application, you can do it in a loop easily and efficiently, using <code>async/await</code> pattern. Try this:</p> <pre><code>async Task DoNavigationAsync() { TaskCompletionSource&lt;bool&gt; tcsNavigation = null; TaskCompletionSource&lt;bool&gt; tcsDocument = null; this.WB.Navigated += (s, e) =&gt; { if (tcsNavigation.Task.IsCompleted) return; tcsNavigation.SetResult(true); }; this.WB.DocumentCompleted += (s, e) =&gt; { if (this.WB.ReadyState != WebBrowserReadyState.Complete) return; if (tcsDocument.Task.IsCompleted) return; tcsDocument.SetResult(true); }; for (var i = 0; i &lt;= 21; i++) { tcsNavigation = new TaskCompletionSource&lt;bool&gt;(); tcsDocument = new TaskCompletionSource&lt;bool&gt;(); this.WB.Navigate("http://www.example.com?i=" + i.ToString()); await tcsNavigation.Task; Debug.Print("Navigated: {0}", this.WB.Document.Url); // navigation completed, but the document may still be loading await tcsDocument.Task; Debug.Print("Loaded: {0}", this.WB.DocumentText); // the document has been fully loaded, you can access DOM here } } </code></pre> <p>Now, it's important to understand that <code>DoNavigationAsync</code> executes asynchronously. Here's how you'd call it from <code>Form_Load</code> and handle the completion of it:</p> <pre><code>void Form_Load(object sender, EventArgs e) { var task = DoNavigationAsync(); task.ContinueWith((t) =&gt; { MessageBox.Show("Navigation done!"); }, TaskScheduler.FromCurrentSynchronizationContext()); } </code></pre> <p>I've answered a similar question <a href="https://stackoverflow.com/questions/18280487/flow-of-webbrowser-navigate-and-invokescript/18283479">here</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload