我想写程序将检查代理...我想用mutlithreading但不`吨真的知道如何将它应用到我的程序:多线程与检查
int ktory = 0;
// Button to start multithreading
private void p_check_Click(object sender, EventArgs e)
{
for (int i = 0; i < 10; i++)
{
Thread th = new Thread(test_proxy);
CheckForIllegalCrossThreadCalls = false;
th.Start();
}
}
//This is my function to test proxies
private void test_proxy()
{
try
{
int ile = p_listbox.Items.Count;
string proxy = null;
//'ktory' - means position in listbox
proxy = p_listbox.Items[ktory].ToString();
ktory += 1;
//Splitting on IP and PORT
int gdzie = proxy.IndexOf(":");
string IP = proxy.Remove(gdzie);
string ipp = proxy.Replace(IP + ":", "");
int PORT = Int32.Parse(ipp);
//end o splitting
//My testing of anonimty (works good don`t need to check)
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(p_proxyjudge.Text);
WebProxy adr_proxy = new WebProxy(IP, PORT);
adr_proxy.UseDefaultCredentials = true;
request.Proxy = adr_proxy;
request.Timeout = 15000;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream stream = response.GetResponseStream();
// Checking if anonymous (not important)
StreamReader sr = new StreamReader(stream);
while (sr.EndOfStream != true)
{
string checking = sr.ReadLine();
if (!checking.Contains("REMOTE_ADDR ="))
p_work.Items.Add(proxy);
}
sr.Close();
stream.Close();
}
catch (Exception ex)
{
ktory += 1;
}
}
<代码:Ile和ktory就像I或J众多变量>
但在10个第一代理我的多线程停止或只是检查它们10X次为一...
的主要问题是让10个机器人检查代理并在完成检查一个代理移动到另一个之后在列表框(但还有一些机器人在后台运行)
请帮我:)我真的就可以坐在第2天,不能弄明白
CheckForIllegalCrossThreadCalls = false; ...这可能不是一个好主意。您可能想要了解如何从线程正确访问控件。代表,调用等 – 2011-04-25 16:03:50
您只创建10个线程来调用该函数,因此它们只能运行10次。另外,'ktory + = 1;'不是线程安全的。没有看过其余的代码,但这就是为什么你看到你提到的结果。 – Rob 2011-04-25 16:04:27
希望你不要使用垃圾邮件 – Poma 2011-04-25 16:04:38