我制作了代理检查程序,由于某种原因,它的工作速度非常慢,我尝试使用100个线程,但仍然工作得很慢。
如何让它更快地运作?
代码:
WebProxy myproxy;
Parallel.ForEach(
PROXIES,
new ParallelOptions { MaxDegreeOfParallelism = 200 },
proxy =>
{
try
{
myproxy = new WebProxy(proxy);
WebRequest request = WebRequest.Create("https://www.google.co.il/");
request.Timeout = TimeOut;
request.Proxy = myproxy;
WebResponse re = request.GetResponse();
this.Invoke((Action)delegate
{
richTextBox1.AppendText(proxy + "\r\n");
});
Good++;
this.Invoke((Action)delegate
{
label3.Text = "Good: " + Good.ToString();
});
}
catch (Exception)
{
Bad++;
this.Invoke((Action)delegate
{
label4.Text = "Bad: " + Good.ToString();
});
}
});