PerformanceCounter not working... RRS feed

  • 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)
          return (value);


    I am calling this method from my form's timer tick event.


    WHats wrong with this code...?






    • Edited by IamHuM Friday, April 16, 2010 6:34 PM Modified the code.
    • Moved by Rudedog2 Friday, April 16, 2010 7:36 PM : Wrong Forum for Topic (From:Visual C# General)
    Friday, April 16, 2010 6:32 PM

All replies