我做了一个代理检查器,但是,因为我使用了Parallel.foreach循环,所以X倍的时间之后,我得到了一个错误,程序只是崩溃了。
它表示该文字已经被另一个进程使用,这是我的代码:
public static void Check()
{
Proxy.Load();
ThreadPool.SetMinThreads(Program.Threads, Program.Threads); // For example 100, 100
ThreadPool.SetMaxThreads(Program.Threads, Program.Threads); // For example 100, 100
Parallel.ForEach(Proxy.Proxies, proxy =>
{
using (var request = new HttpRequest())
{
try
{
request.UserAgent =
"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.183 Safari/537.36 Viv/1.96.1147.52";
request.Proxy = HttpProxyClient.Parse(proxy);
request.ConnectTimeout = Program.TimeOut;
var Post = request.Post("http://209.250.244.126/judge/");
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine($"[+] {proxy} - HTTP");
HTTP.Add(proxy);
}
catch
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"[-] {proxy}");
}
}
// Write the Good proxies to the text file
File.WriteAllLines(Environment.CurrentDirectory + "/Good.txt", HTTP);
});
}
我需要它做什么:
我想在检查运行时将所有Good代理写入文本文件,但我仍然想使用线程使检查更快。