I have this function below and i want to understand this. Also if there any documentations you van point me to. I have read about ManualResetEvent and ThreadPool from msdn
public void GetParametersThreadPool()
{
var toProcess = 50;
ManualResetEvent[] threadsActive = new ManualResetEvent[50];
for (int handleIndex = 0; handleIndex < 50; ++handleIndex)
{
threadsActive[handleIndex] = new ManualResetEvent(false);
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)
{
threadsActive[handleIndex].Set();
}
}), null);
//// Wait for all the threads to complete before starting the next set of requests.
threadsActive[handleIndex].WaitOne();
}
}
When i update this line of code : ManualResetEvent[] threadsActive = new ManualResetEvent[100];
It gives en exception saying less than 64 only.
Currently when i run this stress tests it hangs on the line where i do Logging and doesn't finish running. What am i doing wrong?
If there is any better way to do this? Also just for information i referenced one other question from stackoverflow to create this function on my own