Asked by:
PerformanceCounter not working...

Question
-
Hi...
I am using PerformanceCounter to get CPU time. Below is the code... I always get the end value as '0'.
Whats wrong with this code?
public static string GetRamPercentage() { PerformanceCounter ramCounter = new PerformanceCounter("Memory", "% Committed Bytes In Use", String.Empty, machineName); string value = String.Format("{0:##0}%", ramCounter.NextValue()); if (ramCounter != null) { ramCounter.Dispose(); } return (value); }
I am calling this method from my form's timer tick event.
WHats wrong with this code...?
Thanks,
IamHuM
Friday, April 16, 2010 6:32 PM
All replies
-
have a look here please: http://stackoverflow.com/questions/278071/how-to-get-the-cpu-usage-in-c
--------------------------------------------------------------------------------------------------------------------
For further inf, try here:
http://msdn.microsoft.com/en-us/library/aa326924(VS.71).aspx
http://msdn.microsoft.com/en-us/library/4y422556(VS.71).aspx
Just Be Humble Malange!Friday, April 16, 2010 6:38 PM -
Try the performance counter forum at social.msdn.microsoft.com/Forums/en-US/perfctr/threads/
The following is signature, not part of post
Please mark the post answered your question as the answer, and mark other helpful posts as helpful.
Visual C++ MVPFriday, April 16, 2010 7:09 PM -
Hi All,
I am using C# and .Net 2.0 here. Can sombody help me with the above code.
Whats the problem in the above code...?
Thanks in advance,
IamHuM
Friday, April 16, 2010 8:54 PM -
Memory\% Committed Bytes in Use will not give you CPU time.
Please clarify what you want to do.
Saturday, April 24, 2010 8:37 PMAnswerer