如何为webBrowser导航事件设置超时

Mon*_*RPG 9 c# browser timeout set navigatetourl

如何为webBrowser导航(url)事件设置超时

c #netframework 4.0

Han*_*ant 12

当然使用Timer.例如:

    public void NavigateTo(Uri url) {
        webBrowser1.Navigate(url);
        timer1.Enabled = true;
    }

    private void timer1_Tick(object sender, EventArgs e) {
        timer1.Enabled = false;
        MessageBox.Show("Timeout on navigation");
    }

    private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) {
        if (e.Url == webBrowser1.Url && timer1.Enabled) {
            timer1.Enabled = false;
            // etc..
        }
    }
Run Code Online (Sandbox Code Playgroud)

  • 呃,不.没有什么可以结束的.只是在别处导航. (2认同)
  • webBrowser1.DocumentText ="已取消"; 会做的. (2认同)