urls.length
waitHandles.waitAll
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Net; namespace LabEx1 { class Program { static void Main(string[] args) { AutoResetEvent[] waitHandles = new AutoResetEvent[urls.length]; int i = 0; foreach (string url in urls) { waitHandles[i] = new AutoResetEvent(false); ThreadInfo ti = new ThreadInfo(url, waitHandles[i]); ThreadPool.QueueUserWorkItem(getPage, ti); i++; waitHandles.waitAll(waitHandles); } } class ThreadInfo { public string url; public AutoResetEvent are; public ThreadInfo(string _url, AutoResetEvent _are) { url = _url; are = _are; } static void getPage(object data) { ThreadInfo ti = (ThreadInfo)data; WebResponse wr = WebRequest.Create(ti.url).GetResponse(); Console.WriteLine(ti.url + ": " + wr.Headers["Content-Length"]); wr.Close(); ti.are.Set(); } } } }
urls.Length
urls
AutoRresetEvent
AutoResetEvent
WaitAll
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)