英语太差了,最近还得恶补音标单词,不过学习起来很有意思,玩游戏一样,期待郭老师后面的模拟 数据库各类课程,老师注意身体。
void Run () {
ProxyInfo p;
while (true) {
if (proxyQueue.TryDequeue (out p)) {
Task.Factory.StartNew (async (o) => {
Proxylnfo info = o as Proxylnfo;
HttpClientHandler handler = new HttpClientHandler ();
handler.UseProxy = true;
handler.Proxy = new WebProxy (info.Ip, info.port);
HttpClient client = new HttpClient (handler);
client.Timeout = new TimeSpan (0, 0, 0, 5); //代理连接不上 代理可以连接上 连接不上百度 超时
client.DefaultRequestHeaders.Add ("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36");
client.DefaultRequestHeaders.Add ("Accept", "*/*");
try {
string rel = await client.GetStringAsync ("http://www.baidu.com");
if (rel.Contains ("京公网安备11000002000001号")) {
p.state = true;
}
else {
}
}
catch (Exception ex) {
Console.WriteLine (ex);
} finally {
//很重要必须要处理,不然资源会直接爆掉
client.Dispose ();
handler.Dispose ();
//ProxyVerifCompleteSuccess?.Invoke(info);
successQueue.Enqueue (info);
}
}, p);
}
else {
sendToUI ();
}
if (successQueue.Count >= 20) {
sendToUI ();
}
Thread.Sleep (200);
}
}
private void sendToUI () {
ProxyInfo info = new ProxyInfo ();
List<ProxyInfo> plist = new List<ProxyInfo> ();
while (successQueue.TryDequeue (out info)) {
plist.Add (info);
}
ProxyVerifyCompleteSuccess?.Invoke (plist);
}
|