Geeks With Blogs
Nouman Zakir while (true) { Post.NewArticle(); }
Environment.TickCount returns a 32-bit signed integer containing the amount of time in milliseconds that has passed since the last time the computer was started. But this value can overflow for systems that stay up for days at a time. To avoid this overflow problem, you can query the "System Up Time" performance counter:

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());
}
 
You need proper privileges to query performance counter.
Posted on Sunday, January 18, 2009 6:13 AM | Back to top


Comments on this post: Performance counter without overflow

# re: Performance counter without overflow
Requesting Gravatar...
This only returns the uptime since last boot OR system resume. You need to dig deeper to find the 'real' original start-up time.

Jim
Left by Jim on Feb 25, 2009 4:01 PM

Your comment:
 (will show your gravatar)


Copyright © Nouman Zakir | Powered by: GeeksWithBlogs.net | Join free