Problem/bug in .net class library
-
I have written some code in C# and I can't understand why it behaves the way it does. It is supposed to retrieve the number of seconds that the computer has been turned on and it looks like this:
PerformanceCounter thePerfCounter = new PerformanceCounter( "System", "System Up Time" );
float systemUpTime = thePerfCounter.NextValue( );The thing is that it always returns 0.0 and I am pretty sure my computer has been up for longer than that... :-) If I call NextValue() a second time it returns the correct uptime though. Does anyone have any idea why it behaves like this? thanks for the help /Mike
-
I have written some code in C# and I can't understand why it behaves the way it does. It is supposed to retrieve the number of seconds that the computer has been turned on and it looks like this:
PerformanceCounter thePerfCounter = new PerformanceCounter( "System", "System Up Time" );
float systemUpTime = thePerfCounter.NextValue( );The thing is that it always returns 0.0 and I am pretty sure my computer has been up for longer than that... :-) If I call NextValue() a second time it returns the correct uptime though. Does anyone have any idea why it behaves like this? thanks for the help /Mike
From the docs.
Note If the calculated value of a counter depends on two counter reads, the first read returns 0.0.
My guess is that the uptime counter requires two reads :) James Sonork ID: 100.11138 - Hasaki "Not be to confused with 'The VD Project'. Which would be a very bad pr0n flick. :-D" - Michael P Butler Jan. 18, 2002
-
From the docs.
Note If the calculated value of a counter depends on two counter reads, the first read returns 0.0.
My guess is that the uptime counter requires two reads :) James Sonork ID: 100.11138 - Hasaki "Not be to confused with 'The VD Project'. Which would be a very bad pr0n flick. :-D" - Michael P Butler Jan. 18, 2002
Yes, I have read that note, but it does not make any sense. Why should I have to read a counter twice to get the system up time?? A related question: I am trying to write the same program in managed C++ but the System::Diagnostics namespace does not contain the PerformanceCounter class. Why? Shouldn't the class library be identical beetween the languages? thanks for the help /Mike
-
Yes, I have read that note, but it does not make any sense. Why should I have to read a counter twice to get the system up time?? A related question: I am trying to write the same program in managed C++ but the System::Diagnostics namespace does not contain the PerformanceCounter class. Why? Shouldn't the class library be identical beetween the languages? thanks for the help /Mike