I am developing a console app.
I want to use a Threadpool to perform web downloads. Here is some fake code.
for (int loop=0; loop< 100; loop++)
{
ThreadPool.QueueUserWorkItem(new WaitCallback(GetPage), pageList[loop]);
}
snip
private static void GetPage(object o)
{
//get the page
}
How do I prevent my code from starting more than two (or ten, or whatever) simultaneous threads?
I have tried
ThreadPool.SetMaxThreads(1, 0);
ThreadPool.SetMinThreads(1, 0);
But they seem to have no impact.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…