0

I know Process class have many properties relative to memory like (Private)WorkingSet(64), PrivateMemorySize64 (byte unit),... I tried to get their value and divide to (1024*1024) to get the MB number of them. It seem like none of them have the value like the Task Manager memory column. Is there a property which has the TM's value?

Andiana
  • 1,912
  • 5
  • 37
  • 73

1 Answers1

1

No, there is no property on Process from which you can get the Task Manager Private Working Set but...

You can retrieve the same value from a performance counter from the original answer there:

using System;
using System.Diagnostics;

class Program {
    static void Main(string[] args) {
        string prcName = Process.GetCurrentProcess().ProcessName;
        var counter = new PerformanceCounter("Process", "Working Set - Private", prcName);
        Console.WriteLine("{0}K", counter.RawValue / 1024);
        Console.ReadLine();
    }
}

As you may not know that the values available in Process do not represent the same thing. The Private Working Set is related to only a subset of memory measured by the PrivateMemorySize64. See the answer there.

In fact, it really depends on what you're trying to achieve.

  • If you want to have the same value as in Task Manager, read the performance counter.
  • If you want to measure the memory used by your application, you should used the Process properties. For example, if you want to known the memory that cannot be shared with other processes, use PrivateMemorySize64.

As the side note, all "non-64" memory related properties on Process are obsolete. You should also definitely read the Process documentation.

For reference Private Working Set is related to what is shown in the column of the same for Task Manager or Process Explorer.

You can refer on Windows documentation or a related question to get the meaning of each task manager column.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Fab
  • 14,327
  • 5
  • 49
  • 68