日期:2014-05-17  浏览次数:21260 次

C#多线程操作list对象,急!!!!
各位大神我如何把这六个list对象同时传入ReadUrlContent这个方法,并能同时启用
 
 
            List<StockInfo> result1 = new List<StockInfo>();
            List<StockInfo> result2 = new List<StockInfo>();
            List<StockInfo> result3 = new List<StockInfo>();
            List<StockInfo> result4 = new List<StockInfo>();
            List<StockInfo> result5 = new List<StockInfo>();
            List<StockInfo> result6 = new List<StockInfo>();
Console.WriteLine("begin1:" + DateTime.Now.ToString()); 
            Thread thread = new Thread(new ParameterizedThreadStart(ReadUrlContent));
            Thread.Sleep(300);
            Console.WriteLine("begin1启动"+DateTime.Now.ToString());
            thread.Start(result1);
            Console.WriteLine("end1启动" + DateTime.Now.ToString());
            Thread thread1 = new Thread(new ParameterizedThreadStart(ReadUrlContent));
            Thread.Sleep(300);
            Console.WriteLine("begin2启动" + DateTime.Now.ToString());
            thread.Start(result2);
            Console.WriteLine("end2启动" + DateTime.Now.ToString());

            Console.WriteLine("end1:" + DateTime.Now.ToString());
    static void ReadUrlContent(object code)
        {
            List<StockInfo> list = (List<StockInfo>)code;
            foreach (var item in list)
            {
                try
                {
                    StringBuilder sb = new StringBuilder();
                    byte[] buf = new byte[8192];
                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://dataapi.eastmoney.com:8080/bbsj/stock.aspx?code=" + code.ToString() + "");
 &nbs