string urlt = webBrowser1.Url.ToString();
Webbrowser1.Navigate("Google.com")
HtmlElement elem;
if (webBrowser1.Document != null)
{
HtmlElementCollection elems = webBrowser1.Document.GetElementsByTagName("HTML");
if (elems.Count == 1)
{
elem = elems[0];
string pageSource = elem.InnerHtml;
if (pageSource == "404" || pageSource == "Inter" || pageSource == "siteblocked")
{
}
else
{
Ret2.Add("Page.." + "Url..." + urlt);
}
Am Using above mentioned code for reading WebPage at "DocumentCompleted" Event But If I am Using "For loop" for more then one Url It not calling to DocumentCompleted Event everytime Please suggest if any good idea.
From the comment:
If you can't use
async/await
, then you can't usefor
loop for asynchronousWebBrowser
navigation, unless resorting to deprecated hacks withDoEvents
. Use the state pattern, that's what C# 5.0 compiler generates behind the scene forasync/await
.Alternatively, if you're adventurous enough, you can simulate
async/await
withyield
, as described here.Updated, below is another way of exploiting the C# enumerator state machine (compatible with C# 2.0 and later):