【问题标题】:Is there a C# Process class's property equal to Task manager memory column?是否有 C# Process 类的属性等于任务管理器内存列?
【发布时间】:2016-06-07 15:40:15
【问题描述】:

我知道 Process 类有许多与内存相关的属性,例如 (Private)WorkingSet(64)、PrivateMemorySize64(字节单位)……我试图获取它们的值并除以 (1024*1024) 以获得 MB 数其中。似乎它们都没有像任务管理器内存列那样的值。是否有具有 TM 价值的属性?

【问题讨论】:

    标签: c# memory process taskmanager


    【解决方案1】:

    不,进程上没有可以从中获取任务管理器私有工作集的属性,但是...

    您可以从the original answer there 的性能计数器中检索相同的值:

    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();
        }
    }
    

    您可能不知道 Process 中可用的值并不代表同一事物。 Private Working Set 仅与由 PrivateMemorySize64 测量的内存子集相关。见答案there

    事实上,这真的取决于你想要达到的目标。

    • 如果您想获得与任务管理器中相同的值,请读取性能计数器。
    • 如果要测量应用程序使用的内存,则应使用 Process 属性。例如,如果您想知道无法与其他进程共享的内存,请使用PrivateMemorySize64

    作为旁注,Process 上的所有“非 64”内存相关属性都已过时。您还应该阅读Process documentation

    供参考私人工作集与任务管理器或Process Explorer的同一列中显示的内容相关。

    您可以参考Windows documentationrelated question 以了解每个任务管理器列的含义。

    【讨论】:

    • C# Process 类没有 PrivateWorkingSet 属性
    猜你喜欢
    • 1970-01-01
    • 2011-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-02
    • 2019-11-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多