How do I calculate the private working set of memory using C#? I’m interested in producing roughly the same figures as taskmgr.exe.
I’m using the Process namespace and using methods/data like WorkingSet64 and PrivateMemorySize64, but these figures are off by 100MB or more at times.
This is a highly variable number, you cannot calculate it. The Windows memory manager constantly swaps pages in and out of RAM. TaskMgr.exe gets it from a performance counter. You can get the same number like this:
Do beware that the number really doesn’t mean much, it will drop when other processes get started and compete for RAM.