title: Launch JavaScript from Website / Exit Application
body: <p>Long story short, it's about a Windows Form Application with a WebBrowser control. The application opens a website, fills in username and password, logs in, launches a vpn client (exe) by executing a javascript. Once the vpn client is successfully started, the application should exit. The first half is working fine.</p>
  
  <p>I'd like to check if the vpn client is running, if so, it should close the my application, otherwise wait for the exe to start.</p>
  
  <pre><code>private void LaunchJS()
          {
              HtmlDocument doc = webBrowser1.Document;
              Object js = doc.InvokeScript("launchJS");
              label1.Text = "complete";
          }
  </code></pre>
  
  <p>.</p>
  
  <pre><code>if (label1.Text == ("complete"))
              {
              bool prc = false;
              while (!prc)
              {
                  foreach (Process clsProcess in Process.GetProcesses())
                  {
                      if (clsProcess.ProcessName.Contains("JS_plugin"))
                      {
                          prc = true;
                          Application.Exit();
                      }
                  }
              }
              }
  </code></pre>
  
  <p>The Problem I'm experiencing is that the javascript launch is unsuccessful, when I enable the second part (check process) of the code. The java script isn't executed, the program will never launch and the check process goes into an infinite loop.</p>
  
  <p>Any help would be much appreciated!</p>