static void Main(string[] args)
{
//...
for (int i = 0; i < 100; i++)
{
ThreadPool.QueueUserWorkItem(Worker);
}
jobDone.WaitOne();
}
static void Worker(object state)
{
while(true)
{
int i = Interlocked.Increment(ref currentAddressIndex);
if( i >= addresses.Length) break;
results[i] = GetDataFromServer(addresses[i]);
}
jobDone.Set();
}
static string[] addresses = new string[1000];
static string[] results = new string[1000];
static ManualResetEvent jobDone = new ManualResetEvent(false);
static int currentAddressIndex = 0;
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。