title: C# Get used memory in %
body: <p>I've created a performancecounter that can check the total memory usage in %, but the problem is that it doesn't give me the same value as in task manager shows me. for example: my program says 34% but task manager says 40%.</p>
  
  <p>Any ideas?</p>
  
  <p><strong>NOTE</strong><br>
  I try to get the available RAM of the system, not the used RAM by a process.</p>
  
  <p><strong>Current Code</strong></p>
  
  <pre><code>private PerformanceCounter performanceCounterRAM = new PerformanceCounter();
  
  performanceCounterRAM.CounterName = "% Committed Bytes In Use";
  performanceCounterRAM.CategoryName = "Memory";
  
  progressBarRAM.Value = (int)(performanceCounterRAM.NextValue());
              labelRAM.Text = "RAM: " + progressBarRAM.Value.ToString(CultureInfo.InvariantCulture) + "%";
  </code></pre>
  
  <p><strong>EDIT</strong><br>
  I refresh the progressbar and the label every second with a timer.</p>