Imashi Ekanayaka
Imashi Ekanayaka

Reputation: 33

how to keep a delay line by line in web browser

hi i want to keep a delay to line by line for 5 seconds . I used following code but it is not working.

 private void button3_Click(object sender, System.EventArgs e)
 {
        textBox4.Text = textBox3.Text;
        string[] groups = textBox4.Text.Split('\n');

        webBrowser1.Navigate("https://mbasic.facebook.com/groups/516524655403741");
        Thread.Sleep(5000);
        webBrowser1.Navigate("https://mbasic.facebook.com/groups/548734261950831");
        Thread.Sleep(5000);
        webBrowser1.Navigate("https://mbasic.facebook.com/groups/202669939887242");
        Thread.Sleep(5000);
        webBrowser1.Navigate("https://mbasic.facebook.com/groups/259531940895144");
        Thread.Sleep(5000);
}

After executing this code. it got 20 seconds to redirect to last website...

But i want to run all website within 5 seconds to 5 seconds.. Please fix my issue.

Upvotes: 0

Views: 45

Answers (1)

Progman
Progman

Reputation: 19555

The problem is not the webbrowser client you are using. The problem is that you are blocking the "GUI thread" by a total of 20 seconds. During these 20 seconds now GUI updates will take place until your button3_Click() method finishes.

Rewrite your code that a different thread is executing the Sleep() and Navigate() methods. You might need to use the Dispatcher.Invoke() method to get access to the "GUI thread" again, when you want to update the GUI from a non-"GUI thread".

Upvotes: 3

Related Questions