Using PerformanceCounter to track memory and CPU usage per process?

前端 未结 3 1233
耶瑟儿~
耶瑟儿~ 2020-12-01 02:51

How can I use System.Diagnostics.PerformanceCounter to track the memory and CPU usage for a process?

3条回答
  •  悲&欢浪女
    2020-12-01 03:34

    If you are using .NET Core, the System.Diagnostics.PerformanceCounter is not an option. Try this instead:

    System.Diagnostics.Process p = System.Diagnostics.Process.GetCurrentProcess();
    long ram = p.WorkingSet64;
    Console.WriteLine($"RAM: {ram/1024/1024} MB");
    

提交回复
热议问题