title: Using PerformanceCounter.GetNext()
body: <p>Can anybody tell me why this doesn't work. My guess is its something to do with instantiation or the global values.</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Diagnostics;
  using System.Threading;
  using System.Speech.Synthesis;
  
  namespace UtilApp
  {
      class Perf
      {
          #region Performance Counters
          // CPU utilization
          PerformanceCounter CPU_Perf = new PerformanceCounter("Processor Information", "% Processor Time", "_Total");
          // Memory left
          PerformanceCounter MEM_Perf = new PerformanceCounter("Memory", "Available MBytes");
          // System Up time
          PerformanceCounter SYS_Perf = new PerformanceCounter("System", "System Up Time");
          #endregion
  
          public int getUsedCPU()
          {
              Console.WriteLine("Requested CPU Usage...");
              int v = (int) CPU_Perf.NextValue();
              Console.WriteLine("Value: {0}", v);
              return v;
          }
  
          public int getFreeMEM()
          {
              return (int) MEM_Perf.NextValue();
          }
  
          public int getUpTime()
          {
              return (int) SYS_Perf.NextValue();
          }
      }
  }
  </code></pre>
  
  <p>Basically, getUsedCPU() always returns 0, when I know that is not true. I copied this over from a console application I built using a tutorial online. </p>
  
  <p>I'm accessing it from a form to show CPU usage like so...</p>
  
  <pre><code>Perf p = new Perf;
  label1.text = p.getUsedCPU().toString();
  </code></pre>
  
  <p>NOTE: the console.writeline are for debugging, but still get 0 without them. </p>