What you are looking for is called a Producer-Consumer Model . You have a resource pool that contains a list of URLs to check, one thread can fill this pool, and your conumer threads can pull out of this pool if you have .NET 4 Parallel.ForEach does most of the work for you.
Using 100 threads will also most likely not be the optimal number of threads, just let the parallel task library manage the number of threads for you.
Here is an example if the list is pre-populated and no more items are added when the stream starts.
public void StartThreads()
{
List<string> myListOfUrls = GetUrls();
Parallel.Foreach(myListOfUrls, ProcessUrl);
}
private void ProcessUrl(string url)
{
}
If you need to fill the collection when it starts, replace it List<string>with a parallel collection, for example BlockingCollection
BlockingCollection<string> myListOfUrls = new BlockingCollection();
public void StartThreads()
{
if(myListOfUrls.IsComplete == true)
{
throw new InvalidOperationException();
}
var partitioner = Partitioner.Create(myListOfUrls.GetConsumingEnumerable(), EnumerablePartitionerOptions.NoBuffering);
Parallel.ForEach(partitioner, ProcessUrl);
}
public void StopThreads()
{
myListOfUrls.CompletedAdding()
}
public void AddUrl(string url)
{
myListOfUrls.Add(url);
}
private void ProcessUrl(string url)
{
}
, , , .
, / 100 , : Core 2GB RAM XP Parallel.Foreach 5 ( ThreadPool.SetMinThreads) 100 30-40% . Parallel.Foreach. PS: WebClient wc = new WebClient(); var s = wc.DownloadString(url); ( google) - L.B