我正在使用Docker Desktop for Windows在 windows docker 容器中运行 .net 应用程序。当我的应用程序尝试使用此代码创建性能计数器时:
_counter = new PerformanceCounter(categoryName, counterName, InstanceName, true);
//My categoryname is Processor , CounterName is % Processor Time & instancename is _Total.
我得到了这个例外:
未处理的异常:System.InvalidOperationException:类别不存在。在 System.Diagnostics.PerformanceCounterLib.CounterExists(String machine, String category, String counter) at System.Diagnostics.PerformanceCounter.InitializeImpl() at System.Diagnostics.PerformanceCounter..ctor(String categoryName, String counterName, String instanceName, Boolean readOnly)
这是我的容器的基本映像:https ://hub.docker.com/r/microsoft/dotnet-framework/
它具有 Windows Server 核心作为其中的一部分。
感谢解决此问题的任何帮助。我不确定这是否只是我需要在此处更改的一些 Windows 设置,还是因为 docker & windows 或我的代码无法访问性能计数器的类别。
当我在本地机器而不是容器中运行它时,它工作得很好。