I've got a .Net C# application where I'm attempting to spawn multiple threads. The application is for performance testing and is a simple console app. The piece for spawning threads works fine.
What I'm looking for is the correct mechanism fo either being notified when all the threads complete execution, or waiting within my application for all the threads to complete. At the point I will print out the summary of the results.
Here is what my code snippet looks like:
String testName = "foo";
String fullTestName;
// Iterate and create threads
for (int index = 0; index < numberOfThreads; index++)
{
fullTestName = String.Format("{0}Thread{1}", testName, index);
Thread thread = new Thread(() => PerformanceTest(fullTestName, index, numberOfRows, testToRun));
thread.IsBackground = true;
thread.Name = fullTestName;
thread.Start();
}
void PerformanceTest(String testName, int iterationNumber, long numberOfRows)
{
// Insert a bunch of rows into DB
}
I've looked at using RegisterWaitForSingleObject(), but could not figure out how to use it with my scenario.