using System;
using System.Threading;
public delegate void LoadingProgressCallback(double PercentComplete,string ItemName);
public delegate void
One thing that immediately comes to mind looking at the code is lack of use of Interlocked.
You have to use it otherwise you will see strange errors and behaviours.
So instead of
numThreads++;
Use:
Interlocked.Increment(ref numThreads);
You're closing over the loop variable, which gives you an unexpected result. Try this instead:
foreach(string item in Items)
{
string item2 = item;
Console.WriteLine("Adding {0} to ThreadPool", item2);
ThreadPool.QueueUserWorkItem
(
delegate
{
Load(item2, this.progCall, this.compCall);
}
);
numThreads++;
Thread.Sleep(100);//Remove this line
}
References