I am trying to get the memory usage of my application but for some reason i am getting different size than in task manager
I am using:
Task manager shows that my application occupies 45mb , while when i pulling it in my code i get 85mb how can i get the same size as in task manager (without using wmi)
While the Task Manager is open, you'll see a Task Manager icon in your notification area. This shows you how much CPU (central processing unit) resources are currently in use on your system, and you can mouse over it to see memory, disk, and network usage.
Memory — a continuously updated display of how much of your RAM is being used by each process and each user at the given moment. Total memory usage is shown in the column header.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With