views:

44

answers:

1

I wrote that little program:

string sciezka = "http://proxyjudge.hell-spy.de/";

        foreach(var ip in listBox1.Items)
        {
            ////////////////// CHANGES IP:PORT TO WEBPROXY HOST,PORT
            string host=null;
            string zmiana=null;
            string sport = null;
            int port=0;
            int pozycja=0;
            zmiana=ip.ToString();
            pozycja=zmiana.IndexOf(":");
            host=zmiana.Remove(pozycja);
            sport = zmiana.Replace(host + ":", "");
            port = int.Parse(sport);
            ////////////////////////////////////////// CONNECTING TO PROXYJUDGE
            string anonymous=null;
            try
            {
                WebRequest request = WebRequest.Create(sciezka);
                WebProxy myprox = new WebProxy(host, port);
                request.Timeout = 5000;
                request.Proxy = myprox;
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                Stream strumien = response.GetResponseStream();
                StreamReader sr = new StreamReader(strumien);
                anonymous = sr.ReadToEnd();
                if (anonymous.Contains("HTTP_VIA"))
                {
                    listBox3.Items.Add(zmiana);
                }
                else
                {
                    listBox2.Items.Add(zmiana);
                }
                Update();
                request.Abort();

                sr.Close();
            }
            catch (Exception ex)
            {
                listBox3.Items.Add(zmiana);
                Update();

            }

and I want that it check few proxies at the same time... not one by one :) can someone help with that?

A: 

well, you could use the .AsParallel extension method.

change

foreach(var ip in listBox1.Items)

to

foreach(var ip in listBox1.Items.AsParallel())
David
Is there other way if I`m using .Net 3.5?
You can use the parallel extensions for framework 3.5, but thats a bit more code involved, see http://msdn.microsoft.com/en-us/concurrency/default.aspx, download for it is http://download.microsoft.com/download/4/8/3/483A7420-197B-4C47-B7AF-DC1EB0026C0E/Rx_Net35.msi
David
thank U:) for help