我正在创建一个简单的自动冲浪应用来学习WebBrowser对象。等待WebBrowser加载定时器
我有一个列表,我每冲浪几秒钟就有23个网址。
该应用程序很简单,去论坛,并打开表格添加新消息(不发送它) 并继续前进,直到你到达列表的末尾。
我的问题是代码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++;
}
(对不起,我的英语)
这项工作,但当它结束计时器重新开始,即使我说(当timesToRun是23)设置timesToRun为0,并停止计时器 – samy
我添加了一个解决方案,我的代码。 –