I’m creating a simple auto surfing app to learn the WebBrowser object.
I’ve got a list of 23 URL’s that I’m surfing every few seconds.
The app is simple, go to a forum and open the FORM to add new message (without sending it)
and keep going until you get to the end of the list.
My problem is that the code forumAction.FillOutFormIn(webBrowser1.Document); executes in the wrong site.
I think that this happened because the document is not ready.
So is there a way to stop the timer excuting code until the document is ready?
Here is the TIMER TICK function:
//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++;
}
(sorry for my english)
You could simply code the DocumentCompleted event of the control.
This will allow you to restart the timer when the page is loaded.