Getting a process's ram usage

前端 未结 4 1960
刺人心
刺人心 2020-12-14 07:22

I have been having some trouble figuring out how exactly I get a process\'s ram usage. (How much ram it is currently consuming, not how much is reserved, or its max or min)<

4条回答
  •  离开以前
    2020-12-14 08:13

    I found this on msdn and it is working

    System.Diagnostics.Process proc = ...; // assign your process here :-)
    
    int memsize = 0; // memsize in KB
    PerformanceCounter PC = new PerformanceCounter();
    PC.CategoryName = "Process";
    PC.CounterName = "Working Set - Private";
    PC.InstanceName = proc.ProcessName;
    memsize = Convert.ToInt32(PC.NextValue()) / (int)(1024);
    PC.Close();
    PC.Dispose();
    

提交回复
热议问题