各位大神我如何把这六个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() + "");
                    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                    Stream resStream = response.GetResponseStream();
                    string tempString = null;
                    int totalcount = 0;
                    int count = 0;
                    using (FileStream fs = new FileStream(@"D:\eastmoney\data\bbsj\page\" + item.StockCode + ".html", FileMode.OpenOrCreate, FileAccess.Write))
                    {
                        do
                        {
                            count = resStream.Read(buf, 0, buf.Length);
                            if (count != 0)
                            {
                                tempString = Encoding.ASCII.GetString(buf, 0, count);
                                fs.Write(buf, 0, count);
                            }
                            totalcount += count;
                        }
                        while (count > 0);
                        resStream.Close();
                        response.Close();
                        fs.Close();
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message + code);
                }
            }
        }
多线程c#httpwebrequest对象

解决方案 »

  1.   

    用 object[]参数或者List<object>类型参数
      

  2.   

    我把参数换了,就提示与错误 “ReadUrlContent”的重载均与委托“System.Threading.ParameterizedThreadStart”不匹配StockApplication
      

  3.   

    ReadUrlContent 下的
    StockInfo
    都要换成object
      

  4.   

    全部传进去遍历
    List<List<StockInfo>> list = (List<List<StockInfo>>)code;
      

  5.   

    这跟多线程没什么关系吧。你用List<List<StockInfo>> resultLists = new List<List<StockInfo>>();
    然后,resultLists .Add(results1), results2等等。把resultLists 传参过去。static void ReadUrlContent(object code)方法中 List<List<StockInfo>> lists = (List<List<StockInfo>> )code;
      

  6.   

     ..............Thread thread = new Thread(new ParameterizedThreadStart(ReadUrlContent));
     thread.Start(new object[] { result1, result2, result3, result4, result5});static void ReadUrlContent(object code)
    {
               object[] objs = code as object[];
                List<StockInfo> result1= (List<StockInfo>)objs[0];
                List<StockInfo> result2= (List<StockInfo>)objs[1];
               List<StockInfo> result3=  (List<StockInfo>)objs[2];
               List<StockInfo> result4 = (List<StockInfo>)objs[3];
    }直接复制用 给你改了