Note that there are some explanatory texts on larger screens.

plurals
  1. POWebBrowser control executing from service issue
    primarykey
    data
    text
    <p>Ok, so here's the deal -- I'm running a Windows Forms <code>WebBrowser</code> control from a service. I know thats a no-no, but it seems to work alright.</p> <p>The only thing I'm running into a problem with is trying to wait for the browser's pages to load. In a normal application, I'd just do something like</p> <pre><code>while (browser.readystate != complete) Application.DoEvents() </code></pre> <p>Obviously this won't work from a service.</p> <p>I've tried this as an alternative:</p> <pre><code>public class WebCrawler { private class ExposedActiveXWebBrowser : System.Windows.Forms.WebBrowser { public SHDocVw.WebBrowser UnderlyingWebBrowser { get { return ActiveXInstance as SHDocVw.WebBrowser; } } } ExposedActiveXWebBrowser worker; public WebBrowserReadyState ReadyState { get { return worker.ReadyState; } } public HtmlDocument Document { get { return worker.Document; } } public WebCrawler() { worker = new ExposedActiveXWebBrowser(); } public void Navigate(string urlString) { worker.Navigate(urlString); while (worker.UnderlyingWebBrowser.ReadyState != tagREADYSTATE.READYSTATE_COMPLETE) Thread.Sleep(0); } } </code></pre> <p>That Navigate method, however, doesn't work. The ReadyState never changes from LOADING.</p> <p>What I'm wondering is this -- Windows forms WebBrowsers seem to be inherently asynchronous, so does that mean the ActiveX control is already executing on its own thread? </p> <p><strong>Can I, by accessing the underlying activex control through an appropriate interface, just wait for it to complete?</strong></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