Nouman Zakir
while (true) { Post.NewArticle(); }
posts - 13, comments - 12, trackbacks - 0
My Links
Home
Contact
Login
News
Archives
August, 2009 (2)
February, 2009 (7)
January, 2009 (4)
Post Categories
SQL
(rss)
Windows
(rss)
Personal Website
Nouman Zakir (homepage)
Nouman Zakir (LinkedIn Profile)
<< Save Configuration Settings in Registry
|
Home
|
Log uncaught application exceptions >>
Performance counter without overflow
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.
Print
| posted on Sunday, January 18, 2009 6:13 AM |
Feedback
#
re: Performance counter without overflow
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
2/25/2009 4:01 PM |
Jim
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
Remember Me?
Powered by:
Copyright © Nouman Zakir