简体   繁体   English

等待WebBrowser完成过程

[英]Wait for WebBrowser to finish process

What's the best way to code in a wait for the browser to finish process before continuing? 在等待浏览器完成过程然后继续之前,最好的编码方式是什么? I tried this code below and the process is not waiting till its complete before processing the next link. 我在下面尝试了此代码,在处理下一个链接之前,该过程不会等到完成。

    void WaitBrowserLoading()
    {
        while (webBrowser1.IsBusy)
            Application.DoEvents();
        for (int i = 0; i < 500; i++)
            if (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
            {
                Application.DoEvents();
                lblStoreID.Text = "";
                //System.Threading.Thread.Sleep(5);
            }
            else
                break;
        Application.DoEvents();
    }

Do the Navigated or DocumentCompleted events do what you want? NavigatedDocumentCompleted事件是您想要的吗? I suspect the latter is more appropriate for you: 我怀疑后者更适合您:

Handle the DocumentCompleted event to receive notification when the new document finishes loading. 处理DocumentCompleted事件,以在新文档完成加载时接收通知。 When the DocumentCompleted event occurs, the new document is fully loaded, which means you can access its contents through the Document, DocumentText, or DocumentStream property. 发生DocumentCompleted事件时,新文档已完全加载,这意味着您可以通过Document,DocumentText或DocumentStream属性访问其内容。

Basically you'd disable all the controls (or whatever you want to "stop") before navigating, then re-enable them when the event fires. 基本上,您需要在导航之前禁用所有控件(或您要“停止”的任何控件),然后在事件触发时重新启用它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM