public long RunClient( SocketImplementationType testType, EndPoint endpoint, int iterations, int bufferSize, int socketInstances) { _log.WriteLine( _format, "Implementation", "Type", "Buffer Size", "Iterations", "Init(ms)", "Connect(ms)", "SendRecv(ms)", "Close(ms)", "Total time"); Task[] tasks = new Task[socketInstances]; char[] charBuffer = new char[bufferSize]; for (int i = 0; i < bufferSize; i++) { checked { charBuffer[i] = (char)(i % 26 + 65); } } string message = new string(charBuffer); Stopwatch timeProgramStart = new Stopwatch(); timeProgramStart.Start(); Parallel.For( 0, socketInstances, (i) => { var test = SocketTestClient.SocketTestClientFactory( _log, testType, endpoint, iterations, message, timeProgramStart); tasks[i] = test.RunTest(); }); Task.WaitAll(tasks); timeProgramStart.Stop(); return(timeProgramStart.ElapsedMilliseconds); }