System.Diagnostics.Stopwatch returns negative numbers in Elapsed… properties

This is a bug. It doesn’t seem to have a lot of attention around it, through, so I’d suggesting following up with that report.

The uninspiring workaround appears to be to ignore negative values:

long elapsedMilliseconds = Math.Max(0, stopwatch.ElapsedMilliseconds);

Leave a Comment