Code is needed that returns in bytes the current application memory as in Task Manager.
The comments below lead to the following result:
Code is needed that returns in bytes the current application memory as in Task Manager.
The comments below lead to the following result:
If you need exactly the value shown in Task Manager, then you can subtract it from the performance counters:
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(); } }
In fact, the Working Set - Private is not really "the amount of memory allocated to the process." By itself, the Working Set is the part of virtual memory that the process has recently accessed and which still corresponds to physical memory. And Working Set - Private is an inseparable part of Working Set.
Those. real consumption of memory, this indicator has a very indirect relationship, because depends not only on the memory allocation in the program, but also on how long the program has been accessing it, and on the general state of memory in the system.
Source: https://ru.stackoverflow.com/questions/545563/
All Articles
(int)System.Diagnostics.Process.GetCurrentProcess().WorkingSet64
seems to be returning bytes in bytes - Alexey ShimanskyProcess myProcess = Process.Start("NotePad.exe"); do { if (!myProcess.HasExited) { myProcess.Refresh(); Console.WriteLine(" physical memory usage: {0}", myProcess.WorkingSet64); } } while (!myProcess.WaitForExit(1000));
Process myProcess = Process.Start("NotePad.exe"); do { if (!myProcess.HasExited) { myProcess.Refresh(); Console.WriteLine(" physical memory usage: {0}", myProcess.WorkingSet64); } } while (!myProcess.WaitForExit(1000));
- Alexey Shimansky