title: How to get average value constantly using performance counter?
body: <p>I am getting the RAM and CPU usage of my PC every second using 1 event handler each that is updating this information. I am directing this information to be printed in a <code>TextBox</code>. It is working fine. </p>
  
  <p>On top of this, I am trying to constantly update the average RAM and average CPU usage. As in after the program has run for 10 seconds, I get the average value by adding the last 10 seconds' RAM values and dividing them by 10. Same for 11 seconds where I divide by 11 secs and so on. </p>
  
  <p>I figure I would need to constantly count the seconds and constantly add the ram count and CPU usage count. I am currently using Performance counter to get the CPU and RAM values. </p>
  
  <p>Can I use the performance counter to get the average too? Please advise. My code is as follows. </p>
  
  <pre><code>class Perform
  {
      private PerformanceCounter cpuCounter;
      private PerformanceCounter ramCounter;
  
      public Perform()
      {
          cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
          ramCounter = new PerformanceCounter("Memory", "Available MBytes");
      }
  
      public float GetCurrentCpuUsage()
      {
          return cpuCounter.NextValue();
      }
  
      public float GetCurrentAvailableRam()
      {
          return ramCounter.NextValue();
      }
  }
  </code></pre>