WebBrowser 개체를 배우기 위해 간단한 자동 서핑 응용 프로그램을 만들고 있습니다.WebBrowser가 타이머에로드되기를 기다리는 중
몇 초마다 서핑하는 23 개의 URL 목록이 있습니다.
응용 프로그램은 간단합니다. 포럼에 가서 양식을 열고 새 메시지를 보내지 않고 (보내지 않고) 그리고 목록의 끝까지 올리십시오.
내 문제는 코드 forumAction.FillOutFormIn(webBrowser1.Document);
이 잘못된 사이트에서 실행된다는 것입니다.
문서가 준비되지 않았기 때문에 이런 일이 발생했다고 생각합니다.
문서가 준비 될 때까지 타이머 실행 코드를 중지 할 수있는 방법이 있습니까?
//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 일 때) sayToRun을 0으로 설정하고 타이머를 중지합니다. – samy
코드에 대한 해결책을 추가했습니다. –