好吧,这个问题我已经找了一整天了。我有一个循环,在其中加载网页并解析它们。
问题是 Application.DoEvents 和 while 循环重置每个变量和计数器 Thread.Sleep() 影响加载网页的线程 AutoResetEvent.WaitOne 也是如此
这是我的代码
private void button1_Click_1(object sender, EventArgs e)
{
//some code...
for (int i = 1; i < div.Children.Count; i++)
{
webview.Navigate(addr);
//wait until page is loaded
html_code.Text += "OK!"; //do further actions
}
}
您注意到我有一个 for
循环,因此上面列出的所有方法都不起作用。我请求你帮我解决我的问题
更新:我找到了解决方案。此处描述 https://stackoverflow.com/a/4271581/1894634
最佳答案
如果您只需要 html 响应,最好使用 WebClient.DownloadString
或 WebClient.DownloadStringAsync
方法
WebClient client = new WebClient ();
//client.Credentials = new NetworkCredential(username, password);
string html_code = client.DownloadString (addr);
关于c# - Web浏览器页面循环加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14032292/