Does Stopwatch have a maximum time it can run?

For managed code, the System.Diagnostics.Stopwatch class uses QPC as its precise time basis.

When QPC is available, which it always is on Windows XP or later.

How often does QPC roll over?

Not less than 100 years from the most recent system boot, and potentially longer based on the underlying hardware timer used. For most applications, rollover isn't a concern.

Acquiring high-resolution time stamps

Assuming Microsoft's Windows .NET implementation, this limit is hardware-specific and may be less than the size of a TimeSpan or a long as the other answers indicated. Still plenty large enough though. Good luck getting your program to run for 100 years!


Stopwatch.Elapsed returns a TimeSpan. From MSDN for the MaxValue of TimeSpan:

The value of this field is equivalent to Int64.MaxValue ticks. The string representation of this value is positive 10675199.02:48:05.4775807, or slightly more than 10,675,199 days.

Tags:

C#