我正在创建一个简单的自动冲浪应用程序来学习 WebBrowser 对象。
我有一个包含 23 个 URL 的列表,我每隔几秒就会浏览一次。
该应用程序很简单,转到论坛并打开表格以添加新消息(不发送)并继续前进,直到您到达列表末尾。
我的问题是代码forumAction.FillOutFormIn(webBrowser1.Document);
在错误的站点中执行。
我认为这是因为文件还没有准备好。
那么有没有办法在文档准备好之前停止计时器执行代码?
这是TIMER TICK
功能:
//I start is in 21 for faster testing.
int timesToRun = 21;
private void Time_Tick(object sender, EventArgs e)
{
Console.WriteLine(timesToRun.ToString());
string currentSite = siteList.GetSiteFromIndex(timesToRun);
webBrowser1.Document.Window.Navigate(currentSite);
//I think I need to wait here until the document is ready
//this line of code doesn't run on timeToRun = 22
forumAction.FillOutFormIn(webBrowser1.Document);
Console.WriteLine(webBrowser1.Url);
timerLabel1.Text = siteList.SiteLists.Count + ">" + timesToRun + "";
if (timesToRun >= siteList.SiteLists.Count - 1)
{
enableControls(true);
timesToRun = 0;
timer.Stop();
Console.WriteLine("done");
}
timesToRun++;
}
(对不起我的英语不好)