I test if my WebBrowser is completed with:
webBrowser2.DocumentCompleted += (s, e) =>
{
// Do stuff
}
The webpage I am accessing as tons of JS files and iframes and stuff, so I use the below function to make sure it's the actual page that's completed loading.
webBrowser2.DocumentCompleted += (s, e) =>
{
if (e.Url.AbsolutePath != (s as WebBrowser).Url.AbsolutePath)
{
return;
}
// Do stuff
}
However, it still doesn't appear to be working. Am I doing something wrong or is this syntactically correct and there's some other error in my code?
DocumentCompleted
fires multiple times on certain pages, i.e. when iframes load, when JS files load, etc. I only want to run my code when the page in it's entirety has loaded. Even with the if test I inserted above, theDocumentCompleted
is still firing multiple times for my pages.if (browser.ReadyState != WebBrowserReadyState.Complete) return
from the first link? Are you still seeingDocumentCompleted
events afterbrowser.ReadyState
becameWebBrowserReadyState.Complete
?