Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set timeout for webBrowser navigate event

how can i set timeout for webBrowser navigate (url) event

c# netframework 4.0

like image 778
MonsterMMORPG Avatar asked Feb 04 '23 01:02

MonsterMMORPG


1 Answers

By using a Timer of course. For example:

    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..
        }
    }
like image 92
Hans Passant Avatar answered Feb 05 '23 14:02

Hans Passant