1.怎么用多线程来解决(长时间执行一个更新的)超时问题 
        就是想页面显示 进度条 
        后台就不断更新数据
      2.更新数据时,我想开几个线程让效率高些
     
        该怎么实现呐。以前没用过多线程,用也是在乱用。。

解决方案 »

  1.   

       public bool SearchWebSites(string url)
        {
            DateTime lStarted = DateTime.Now;
            _pages = new ArrayList();        // split the urls string to an array
            string[] lURLs = url.Split('\r');
            int lIdx;
            searchTitle st;
           
            // create the Thread array
            Thread[] t = new Thread[lURLs.Length];        for (lIdx = 0; lIdx < lURLs.Length; lIdx++)
            {
                // create a WebPage object for each url
                st = new searchTitle(lURLs[lIdx]);
                // add it to the _pages ArrayList
                _pages.Add(st);
               
                t[lIdx] = new Thread(new ThreadStart(st.search));
                // start the Thread object, which executes the search().
                t[lIdx].Start();
                t[lIdx].IsBackground = true;
            }        for (lIdx = 0; lIdx < _pages.Count; lIdx++)
            {
                // waiting for all the Threads to finish.
                t[lIdx].Join();
            }        // stop the timer.
            _timeSpent = DateTime.Now.Subtract(lStarted);        Operation op = new Operation();    
            op.DeleteNowDelete();
           
            return true;
        }
    这里该怎么设置线程数量为20啊??急
      

  2.   

    传入的url,包含20个地址,地址以"\n"为分割,
      

  3.   

    我URL有很多啊,我想让他循环执行这个多线程,但是线程数量要有个限制,该怎么写呐。。
    我现在这么弄,很多数据都不准确,是不是一次执行的线程多了,反应不过来。