private void GetImages()
{
for (int i = 0; i < newHtmls.Count; i++)
{
uri = newHtmls[i];
webBrowser1.Navigate(newHtmls[i]);
}
}
然后
void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (e.Url.ToString() == uri)
{
htmlloaded = true;
MessageBox.Show("fgdsg");
}
}
我尝试使用htmlloaded标志但不确定如何使用。
例如在newHtmls循环中的metohd GetHtmls中我有5个链接。 我希望它会使一个循环在第一个链接导航时仅在完成上传文档并在DocumentCompleted事件中执行其他操作然后返回循环并从newHtmls导航获取第二个链接等待直到事件中的所有事情DocumentCompleted等等。
我从另一个地方调用GetHtmls,每次List newHtmls里面都有不同数量的链接。 每次我想逐一导航到列表中的每个链接。
导航然后等待完成事件中的所有操作,然后导航到列表中的下一个链接。
代码的方式现在它将首先遍历所有newHtmls,并在尝试完成事件之前尝试导航到所有链接。
我刚刚使用了messageBox来查看它是否到达那里并且确实如此。 但是后来我会在每个链接上做很多其他事情。 这就是为什么我需要逐个导航到每个链接等待完成所有内容然后导航到下一个链接。
答案 0 :(得分:0)
您想要的是等待处理的网址列表。您GetImages()
方法应该采用列表中的第一项并对其进行处理。
private void GetImages()
{
uri = urlToProcess.FirstOrDefault();
if (uri != null) // null if there or no more to process
{
webBrowser1.Navigate(uri);
}
}
一旦网络浏览器导航到屏幕webBrowser1_DocumentCompleted
将被调用,因此您需要;按照您的其他要求执行操作,然后从列表中删除该网址并再次致电GetImage()
。
void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (e.Url.ToString() == uri)
{
htmlloaded = true;
MessageBox.Show("fgdsg");
}
urlsToProcess.RemoveAt(0);
GetImages();
}