0
I should have realized how sensitive threads are to timing.
Instead of having aglobal DoneEvents, I need to pass it within this loop immediately because by the time I access it beyond here, it wouls have gotten out of synch. So I bundled that data for my callback into a lightweight class that takes the doevents and the method from within the loop and passes it to my worker method.
The gist of the fix is as follows.
class bundleddata
{
MethodInfo Method;
ManualResetEvent MRE;
}
...
MethodInfo[] aMethods = aTestClass.GetMethods();
int i = 0;
foreach(MethodInfo aMethod in aMethods)
if(aMethod.ReturnType.Name == "Void")
{
bundleddata aBD=new bundleddata();
aDoneEvents[i] = new ManualResetEvent(false);
aBD.Method=aMethod ;
aBD.MRE = aDoneEvents[i];
ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadProc), aBD);
i++;
}