Search code examples
c#.net.net-coresystem.diagnostics

Replace System.Diagnostics into .Net Core 2.0 (C#)


I got method in console app .net 4.6:

using System.Diagnostics;

public static void CPUMonitorTest()
{
   var cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
   ...
}

When try to do it into class library .NET Core 2.0 I got problem:

  • the namespace doesn't exisit

What can I do now?


Solution

  • You need package System.Diagnostics.PerformanceCounter. Install it using package manager or console

    Install-Package System.Diagnostics.PerformanceCounter -Version 4.5.0
    

    enter image description here