.NET 4.x Проверка прокси - C#
Формулировка задачи:
У меня есть небольшой блог где я выкладываю Proxy. Захотелось мне использовать свою программу для проверки Proxy.
Но у меня проблема:
Форма виснит. И как-то странно работает, то null в list находит, то еще что-то.
Для простоты понимания я накидал весь код в Form1
Код ну очень простой и ошибка ну очень простая, только вот уже глаза замусолил ее искать. Нужен свежий взгляд.
Вот проект с Proxy листом, с HideMe, для того кто хочет попробывать.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using xNet;
namespace CheckProxy
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
List<string> list = new List<string>();
public int statProxy, statGood, statBad;
private void btnLoad_Click(object sender, EventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "*.txt|*.txt";
dialog.ShowDialog();
if (File.Exists(dialog.FileName))
{
list.Clear();
list.AddRange(File.ReadAllLines(dialog.FileName));
statProxy = list.Count;
lbProxy.Text = statProxy.ToString();
}
}
private void btnStart_Click(object sender, EventArgs e)
{
timerStat.Interval = 1000;
timerStat.Enabled = true;
logika();
}
private void timerStat_Tick(object sender, EventArgs e)
{
lbProxy.Text = statProxy.ToString();
lbGood.Text = statGood.ToString();
lbBad.Text = statBad.ToString();
if (list.Count == 0)
{
timerStat.Enabled = false;
MessageBox.Show("Закончили Работу", "Готово!", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
public void logika()
{
for (int i = 0; i < 100; i++)
{
Thread th = new Thread(logikaProxy);
th.IsBackground = true;
th.Start();
}
}
public void logikaProxy()
{
while (list.Count > 0)
{
string resp = "";
resp = CheckerProxy(list.ElementAt(0));
if (resp != null && resp == "Bad")
{
statBad++;
statProxy--;
list.RemoveAt(0);
}
if (resp != null && resp.Contains(":"))
{
statGood++;
statProxy--;
list.RemoveAt(0);
}
}
}
public static string CheckerProxy(string prx)
{
using (HttpRequest reqes = new HttpRequest())
{
reqes.UserAgent = Http.FirefoxUserAgent();
reqes.Proxy = HttpProxyClient.Parse(prx);
reqes.ConnectTimeout = 5000;
reqes.Proxy.ConnectTimeout = 5000;
reqes.ReadWriteTimeout = 5000;
reqes.Proxy.ReadWriteTimeout = 5000;
try
{
reqes.Post("https://google.ru");
return prx;
}
catch
{
return "Bad";
}
}
}
}
}Решение задачи: «.NET 4.x Проверка прокси»
textual
Листинг программы
public void logikaProxy()
{
while (list.Count > 0)
{
string resp = "";
resp = CheckerProxy(list.ElementAt(0));
if (resp != null && resp == "Bad")
{
statBad++;
statProxy--;
list.RemoveAt(0);
}
if (resp != null && resp.Contains(":"))
{
statGood++;
statProxy--;
list.RemoveAt(0);
}
Thread.Sleep(1); // тут
}
}