473,382 Members | 1,615 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

PerformanceCounter / System Up Time / TimeSpan

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
May 31 '06 #1
3 2858
The first call always returns zero, apparently... see the page here:
http://www.sitepoint.com/forums/prin...d.php?t=376778
Regards,
Brett.
Rob Meade wrote:
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


May 31 '06 #2
"Brett Wiltshire" wrote ...
The first call always returns zero, apparently... see the page here:
http://www.sitepoint.com/forums/prin...d.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 :o(

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

Thanks

Rob
May 31 '06 #3
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
May 31 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: W1ld0ne74 | last post by:
I am implimenting Performance counters into a web application. I use the following code to create the counters during setup: private void SetupPerfCntrs() {...
1
by: Chris | last post by:
I'm trying to do something really easy: just get the % CPU load. However, I just get mostly 0's sprinkled with an occasional 100. I poked around on the web for info, but all the stuff I found (I...
1
by: jimbo | last post by:
Here is my problem. I'm creating an Instrumentation class that will use previously created Performance Categories and Counters in order to time various processes (ie. query duration etc.). This...
3
by: Ivan A. | last post by:
Hi! Why I can't serialize TimeSpan structure with XmlSerializer? This is what I do: using System; using System.IO; using System.Xml; using System.Xml.Serialization;
4
by: DWW | last post by:
System.DateTime returns a string with the date and time. I want to convert the time to an integer, for example, convert 10:24:45 to 102445. Much research has turned up a myriad of variations on...
2
by: Michael Moreno | last post by:
Good morning, Here is the objective: monitoring the CPU usage of a given thread in my own C# application. Here is what I do: - on a Form I put a PerformanceCounter - I set e CategoryName =...
0
by: Scheu | last post by:
Hi all, I'm hoping someone can help me with this bizarre problem. If I create a new PerformanceCounter object in a ComVisible class and invoke it from wscript, it never seems to terminate. When...
3
by: Geoff McElhanon | last post by:
I have been struggling with a security issue that occurs under .NET 2.0, but does not occur under .NET 1.1. Essentially I am trying to open up a performance counter on a remote server and monitor...
11
by: =?Utf-8?B?U2FsYW1FbGlhcw==?= | last post by:
Has anybody worked with performancecounter object to access counters on remote machine? I managed to write code that retrieves counters categories froma remote machine, when I try another remote...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.