To avoid this overflow problem, you can query the "System Up Time" performance counter:
Code: Select all
public TimeSpan SystemUpTime()
{
PerformanceCounter upTime = new PerformanceCounter("System", "System Up Time");
// You've got to call this twice. First time it returns 0 and the second time it returns the real info.
upTime.NextValue();
return TimeSpan.FromSeconds(upTime.NextValue());
}