title: Invoke a script in WebBrowser, and wait for it to finish running (synchronized)
body: <p>I am using <code>webBrowser.Document.InvokeScript("Function")</code> to run a javascript, located in a local file opened with the Winforms WebBrowser.</p>
  
  <p>The problem is, I need the javascript to finish executing before continuing. How do I wait/listen for that?</p>
  
  <p>This is my C# code:</p>
  
  <pre><code>    private void Button1_ItemClick_1(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
      {
          webBrowser.Document.InvokeScript("Script_A");
          Method_A();
          DialogResult = System.Windows.Forms.DialogResult.OK;
      }
  </code></pre>
  
  <p>Javascript code:</p>
  
  <pre><code>&lt;script&gt;function Script_A() { Script_B(); }&lt;/script&gt;
  </code></pre>
  
  <p>How do I make sure that Method_A is not executed before Script_B has finished?</p>