Wait for WebBrowser to finish process

我的未来我决定 提交于 2019-12-08 08:04:21

问题


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();
    }

回答1:


Do the Navigated or DocumentCompleted events do what you want? I suspect the latter is more appropriate for you:

Handle the DocumentCompleted event to receive notification when the new document finishes loading. 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.

Basically you'd disable all the controls (or whatever you want to "stop") before navigating, then re-enable them when the event fires.



来源:https://stackoverflow.com/questions/7295560/wait-for-webbrowser-to-finish-process

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!