C#多线程无法启动工作/工作?

时间:2016-06-16 20:09:39

标签: c#

出于某种原因,我的线程忽略了我的工作,看起来任何人都有任何想法为什么这样做?非常欢迎帮助,非常感谢,谢谢。这个程序是什么,是一个ProxyChecker,因为我已经买了一堆,并将继续使用不同的用户/通行证等代理,但有些已经过期

        static List<String> user = new List<String>();
        static List<String> pass = new List<String>();
        static List<String> ips = new List<String>();
    static Random rnd = new Random();

    static void Main(string[] args)
    {
        int threads = 4;
        loadips();
        Console.WriteLine("Enter the amount of threads to run (4 default):");
        threads = Int32.Parse(Console.ReadLine());
        Console.WriteLine("Starting on " + threads + " threads...");
        for (int i = 0; i < threads; i++)
        {
            ThreadPool.QueueUserWorkItem(new WaitCallback(CheckProxy), i);
        }
        //Console.ReadLine();
    }
    public class MyIP
    {
        public string IP { get; set; }
        public bool AcceptsConnection { get; set; }
    }

    private static void CheckProxy(object state)
    {
        var u = user[0];
        var p = pass[0];
        var l = new List<MyIP>();
        Parallel.ForEach(l.ToArray(), (item) =>
        {
            string ip = getip();
            try
            {
                using (var client = new ProxyClient(ip, u, p))
                {
                    Console.WriteLine(ip, user, pass);
                    client.Connect();
                    item.AcceptsConnection = client.IsConnected;
                }
            }
            catch
            {
                l.Remove(item);
            }
        });
        foreach (var item in l)
        {
            if (item.AcceptsConnection == true)
            {
                WriteToFile(user[0], pass[0]);
            }
            Console.WriteLine(item.IP + " is " + (item.AcceptsConnection) + " accepts connections" + " doesn not accept connections");
        }
    }



 private static void loadips()
        {
            using (TextReader tr = new StreamReader("ips.txt"))
            {
                string line = null;
                while ((line = tr.ReadLine()) != null)
                {
                    ips.Add(line);
                }
            }
        }

1 个答案:

答案 0 :(得分:0)

您不了解我的代码示例...您应该将IP添加到列表l,而不是getip()方法......所以失去{{1方法

getip()