I have a parallel loop in a console application with a StopWatch.
If I input 10000 loops it says it finishes in 13 seconds but in real world the console doesn't stop printing until 15 minutes later. So how can I properly time this loop so the stopwatch stops after the last line has finished writing to the console? My expected result is "Process took 903 Seconds"
int i = 0;
int N = 10000;
Stopwatch sw = new StopWatch();
sw.Start
Parallel.For(0, N, i =>
{
//Do some logic task here then write to the console
console.Writeline("Thread " + i + " has finished");
});
sw.Stop()
console.WriteLine("Process took" + sw.Elapsed.Seconds + " Seconds");
Is is similar to C# Timespan Milliseconds vs TotalMilliseconds where one used Milliseconds instead of TotalMilliseconds?