WaitOne Blocks the current thread until the current WaitHandle receives a signal, you are writing mulit-thread code but this method is sync method actually
create a variable that keeps track of the number of running tasks:
var toProcess = 50;
create one signal instead of array
ManualResetEvent signal = new ManualResetEvent(false);
for (int handleIndex = 0; handleIndex < 50; ++handleIndex)
{
ThreadPool.QueueUserWorkItem(new WaitCallback(delegate(object state)
{
string reportUrl = TeamFoundationTestConfig.TeamFoundationReportPath("TaskGroupStatus");
ReportUri reportUri = ReportUri.Create(reportUrl);
Log.Message(TraceEventType.Information, "ReportUri = {0}".InvariantFormat(reportUri.UriString));
IList<Parameter> parameters = this.RemoteReportingServiceFactory.CreateReportParameterProvider().GetParameters(reportUri, SessionContext);
Assert.IsNotNull(parameters, "Assertion failed: Parameters cannot be null. GetParameters failed");
Assert.IsTrue(parameters.Count > 0, "Assertion failed: No parameters available on the report page. GetParameters failed. Count = {0}".InvariantFormat(parameters.Count));
if (Interlocked.Decrement(ref toProcess) == 0)
{
signal.Set();
}
}), null);
}
signal.WaitOne();
don't put signal.WaitOne() in the for loop, that will block the thread.
finally, consider use Task if you are working on .net 3.5 or higher