1

I'd like to get the percentage of memory usage of a process.

This is what I currently have:

return new PerformanceCounter("Memory", "% Committed Bytes In Use").NextValue();

However, this is the RAM usage of my whole computer, not only the process.

When trying to add a string parameter to PerformanceCounter, it doesn't work because you apparently can't provide a process name for this counters category.

Sofia
  • 93
  • 1
  • 8
  • _"not only the process"_ - the memory usage of a process is always 100% of the memory usage of that process. Please elaborate on what **exactly** you want to know. – CodeCaster Feb 06 '20 at 12:59

1 Answers1

4

Memory usage of the current process:

System.Diagnostics.Process.GetCurrentProcess().PrivateMemorySize64

Total system memory:

Microsoft.VisualBasic.Devices.ComputerInfo().TotalPhysicalMemory

Multiplying the first one by 100 and dividing the result by the second you get the percentage.

max
  • 466
  • 3
  • 7