WebBrowser component c# waiting time
I have following code
WebBrowser browser = new WebBrowser();
browser.Navigate(link);
Problem is that I need to wait 3 sec before I execute next function (line). I have tried to use Thread.Sleep(3000)
but obviously it doesn't work .
So I'm looking for a way to wait 3 sec before executing next line of code and sill letting bro开发者_Go百科wser navigate to given link
Thread.Sleep()
doesn't work because it doesn't allow for the WebBrowser
events to be processed.
I think what you are really looking for is an event that fires once the page navigation is completed:
WebBrowser browser = new WebBrowser();
browser.DocumentCompleted += (object sender, WebBrowserDocumentCompletedEventArgs e) =>
{
//do your processing here or set completed flag
};
browser.Navigate(link);
I'm not sure where I found it, but this worked for me. I especially don't recall about the Sleep statement.
Browser.Navigate(sLetterFile);
while (Browser.ReadyState != WebBrowserReadyState.Complete)
{
System.Windows.Forms.Application.DoEvents();
}
Thread.Sleep(1000);
精彩评论