The problem is rather strange - if you put sleep less than 700, then somewhere on the 10th iteration, the prog hangs tight. 700 is quite a lot, thinks long ... but it works. The task is quite simple: load the page at the address from the array; click on it; load another ...

my implementation: in the loop we process each element of the array. we load it into the browser. Then we intercept the event that the page is loaded and execute a separate method (presses those buttons). When the method finishes, the wb2scanned = true flag; As soon as the flag works, go to the next iteration ...

but in practice something nonsense turned out (((Either the brake is with sleep (700), or it hangs (though less sleep () - the faster it hangs.

private void _webBrowser2(object sender, WebBrowserProgressChangedEventArgs e) { int max = (int)Math.Max(e.MaximumProgress, e.CurrentProgress); int min = (int)Math.Min(e.MaximumProgress, e.CurrentProgress); if (min.Equals(max) && webBrowser2.Document.GetElementById("body")!=null) //загрузилось? { bool frmtch = true; //защита от повторного срабатываения. if (wb2loaded ==false && frmtch!=false){ wb2loaded = true; filter_start(); //Функция нажатий } } } void Filter_stratClick(object sender, EventArgs e) { webBrowser2.ProgressChanged += new WebBrowserProgressChangedEventHandler(_webBrowser2); foreach(string f in lines){ //lines - массив со ссылками f_id= f.Trim(';'); wb2loaded = false; wb2scanned = false; //в конце своей работы filter_start() присвоит ей true; webBrowser2.Navigate(f_id); //ждем пока загрузит браузер... while(wb2scanned!=true){ Application.DoEvents(); System.Threading.Thread.Sleep(700); } } 
  • Wash is easier for this task to use enumerator with yield. In the application, after clicking, call Next - Serginio

1 answer 1

Use asynchronous code.

 async void Filter_stratClick(object sender, EventArgs e) { // ... wb2scanned = new TaskCompletionSource<object>(); webBrowser2.Navigate(f_id); await wb2scanned.Task; // ... } 

Inside filter_start :

 wb2scanned.SetResult(null); 
  • Did you forget to create the field of the necessary type in the class? .. - Pavel Mayorov
  • I do not exclude, not so long ago with # teach. ((((( - Andrew Bro
  • and how to create it? ) - Andrew Bro
  • uh ... how did you do it before? - Pavel Mayorov