for(int i=0;i<10;i++)
thread th1=new thread(function1)
th1.start(i)
}
public void function1(object obj)
{
}
向线程传递个参数,然后在线程里判断自己是哪个线程
网址可以放全局数组里,然后对应线程去调自己的网址字符串

解决方案 »

  1.   

    或者
    th1 = new Thread(delegate() { function( "http:xxxxx"); });
    th1.Start();private void fun2(string s1)
            {
            }
    直接将字符串当参数传递进去
      

  2.   

    如果你“不能按x1.com,x2.com,x3.com次序访问”,还是别用多线程了。多线程意味着并发执行,因为你不能决定先访问谁后访问谁。注意,并发并不是同时。而是不确定。什么意思呢?也许一开始它们是“同时”的,但是每个线程执行有快慢,在不同步的情况下,到了后来是不能保证它们各自的进度的。而线程同步又回到了单线程。
      

  3.   


    你开了10个线程,如果任务1超过10个页面,那么任务2,3,4 都在等待中了,并不是同时进行啊
    我这只是给你写了个代码例子.具体每个线程分配哪几个页面,得你自己去处理啊.
    你给线程1分配了100个页面,给2-10分配2个页面,那多线程还有什么意义啊.
    你可以用个二维数组,预先存入每个线程要访问的页面url,然后各自去访问各自的页面.
      

  4.   

    http://zhidao.baidu.com/question/96551168.html?qbl=relate_question_0&word=c%B6%E0%CF%DF%B3%CC%CA%B5%C0%FD
      

  5.   

    你是要多线程同步的访问x1.com/001,x2.com/001,x3.com/001
    然后再同步访问x1.com/002,x2.com/002,x3.com/002??
    多线程只是并行处理,如果你一下给每个线程分配10个页面,它们访问速度不一样,最后执行完肯定不是完全同步的
    除非你在主线程里建立个while循环
    每次只给线程分一个页面,等所有线程都执行完,再给它们分下一个页面
      

  6.   

    就只能用我3楼给出的代码,用委托的方式传递个string型的参数进去,告诉线程要访问的url
      

  7.   

    判断线程是否正在执行的属性:
    thread.IsAlaive
      

  8.   

    可以试试异步作业
    private void SumPageSizes()
    {
        // Make a list of web addresses.
        List<string> urlList = SetUpURLList();     var total = 0;
        foreach (var url in urlList)
        {
            // GetURLContents returns the contents of url as a byte array.
            byte[] urlContents = GetURLContents(url);        DisplayResults(url, urlContents);        // Update the total.
            total += urlContents.Length;
        }    // Display the total count for all of the web addresses.
        resultsTextBox.Text += 
            string.Format("\r\n\r\nTotal bytes returned:  {0}\r\n", total);
    }
    private List<string> SetUpURLList()
    {
        var urls = new List<string> 
        { 
            "http://msdn.microsoft.com/library/windows/apps/br211380.aspx",
            "http://msdn.microsoft.com",
            "http://msdn.microsoft.com/en-us/library/hh290136.aspx",
            "http://msdn.microsoft.com/en-us/library/ee256749.aspx",
            "http://msdn.microsoft.com/en-us/library/hh290138.aspx",
            "http://msdn.microsoft.com/en-us/library/hh290140.aspx",
            "http://msdn.microsoft.com/en-us/library/dd470362.aspx",
            "http://msdn.microsoft.com/en-us/library/aa578028.aspx",
            "http://msdn.microsoft.com/en-us/library/ms404677.aspx",
            "http://msdn.microsoft.com/en-us/library/ff730837.aspx"
        };
        return urls;
    }
    private byte[] GetURLContents(string url)
    {
        // The downloaded resource ends up in the variable named content.
        var content = new MemoryStream();    // Initialize an HttpWebRequest for the current URL.
        var webReq = (HttpWebRequest)WebRequest.Create(url);    // Send the request to the Internet resource and wait for
        // the response.
        // Note: you can't use HttpWebRequest.GetResponse in a Windows Store app.
        using (WebResponse response = webReq.GetResponse())
        {
            // Get the data stream that is associated with the specified URL.
            using (Stream responseStream = response.GetResponseStream())
            {
                // Read the bytes in responseStream and copy them to content.  
                responseStream.CopyTo(content);
            }
        }    // Return the result as a byte array.
        return content.ToArray();
    }
    private void DisplayResults(string url, byte[] content)
    {
        // Display the length of each website. The string format 
        // is designed to be used with a monospaced font, such as
        // Lucida Console or Global Monospace.
        var bytes = content.Length;
        // Strip off the "http://".
        var displayURL = url.Replace("http://", "");
        resultsTextBox.Text += string.Format("\n{0,-58} {1,8}", displayURL, bytes);
    }详细内容:
    http://msdn.microsoft.com/zh-cn/library/vstudio/hh300224.aspx