我使用WebBrowser DocumentCompleted事件时遇到了一些问题。 我有这样的代码:WebBrowser和DocumentCompleted事件
int timesToRun = 20;
private void Time_Tick(object sender, EventArgs e)
{
if (timesToRun >= siteList.SiteLists.Count)
{
timesToRun = 0;
webBrowser1.DocumentCompleted -= this.webBrowser1_DocumentCompleted;
Console.WriteLine("timer is done");
timer.Stop();
}
timer.Enabled = false;
Console.WriteLine("timer is now disabled");
Console.WriteLine(timesToRun);
string currentSite = siteList.GetSiteFromIndex(timesToRun);
webBrowser1.Navigate(currentSite);
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
WebBrowser wb = (WebBrowser)sender;
if (e.Url.AbsolutePath != wb.Url.AbsolutePath) //somtimes dosn't return true
{
Console.WriteLine(wb.Url);
forumAction.FillOutFormIn(wb.Document);
timesToRun++;
Console.WriteLine("timer is now enabled");
timer.Enabled = true;
}
}
我的问题是,如果statment是事实,只有somtimes。我不知道还有什么可以检查以确保browswer可以使用。
我还能检查什么? 或者我应该采取一个不同的解决这个问题?
我得到这个,如果从一个不同的问题在这里stackOverFlow的说法,因为我是一个问题,事件被解雇了更多的事情(因为iframe的和东西)。
(对不起,我的英语)
代码没有意义。您可以统计帧数,这与您访问的网站数量无关。如果URL不匹配,则页面尚未完全完成。所以什么也不做。 –
但如果我不检查在DocumentCompleted运行两次(每次最多)代码 – samy