PerformanceCounter / System Up Time / TimeSpan

R

Rob Meade

Hi all,

I'm having a bit of trouble with the following function....

Private Function GetSystemUpTime() As TimeSpan

' declare variables
Dim Result As TimeSpan
Dim PerformanceCounter As PerformanceCounter

' create new instances of our objects
PerformanceCounter = New PerformanceCounter("System", "System Up Time")

' populate
Result = TimeSpan.FromSeconds(PerformanceCounter.NextValue())

' return result
Return Result

End Function

For some reason I keep getting the value 0 (zero) for days, hours,minutes,
seconds etc - ie, I've tried this on 2 machines now and the result is always
the same. I've tried other counters using a similar method (for available
memory,application restarts etc) and they do come through...

Can anyone shed any light on this for me...

PS: I've had a bit of a look online and I'm aware of the environment.tick
thing but that has a problem over a value of 24 (goes to minus numbers) so
would prefer to use a PerformanceCounter object.

Regards

Rob
 
R

Rob Meade

...
The first call always returns zero, apparently... see the page here:
http://www.sitepoint.com/forums/printthread.php?t=376778

Hi Bretty,

Thanks for your reply - you know - in the example I saw that had this code
it actually said about that - I assumed - clearly wrongly - that the
"NextValue()" thing meant - go get the next one because the first one is
always zero...

*sigh*

That's taken up 2 hours of my day searching the net just for a
misunderstanding :eek:(

Anyway, many thanks for your reply - I've for now just duplicated the line
that gets it and it works fine :eek:)

Thanks

Rob
 
R

Rob Meade

Anyone know if its possible to pull the same information from different
machines on the network?

A new instance of PerformanceCounter seems to be able to take a machine
name - but I've tried this and get access denied errors...

I guess i some how need to be able to tell the servers in question that the
ASP.Net process model is allowed to access this?

Any ideas anyone?

My other thought was as a web service, so I have one page which drags the
info from the other servers, this would of course then rely on IIS being
present, not so good for my clustered SQL Servers! Open to suggestions...

Regards

Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top