How to get application memory usage as shown in Task Manager?
Presumably you're looking at the wrong column in "Task manager" or using the wrong property in Process class..
I guess you're looking for WorkingSet64
not PrivateMemorySize64
. PrivateMemorySize64
is the amount of virtual memory allocated for the process, not the physical memory. For physical memory use WorkingSet64
.
Also, you need to call process.Refresh()
before accessing any of the dynamic properties in process class as it is heavily cached.
process.Refresh();
_data.MemoryUsed = (process.WorkingSet64).ConvertBytesToMegabytes().ToString(CultureInfo.InvariantCulture);