代码之家  ›  专栏  ›  技术社区  ›  smarty

当PerformanceCounter未作为服务运行时

  •  0
  • smarty  · 技术社区  · 7 年前
    Unhandled error: Counter '% Processor Time' does not exist in the specified Category. - Counter '% Processor Time' does not exist in the specified Category. System.InvalidOperationException System.Diagnostics.CounterDefinitionSample GetCounterDefinitionSample(System.String)    at System.Diagnostics.CategorySample.GetCounterDefinitionSample(String counter)
       at System.Diagnostics.PerformanceCounter.NextSample()
       at System.Diagnostics.PerformanceCounter.NextValue()
    

    PerformanceCounter cpuCounter = new PerformanceCounter("Process", "% Processor Time", "_Total");
    double cpu = cpuCounter.NextValue();
    

    我把这两行代码放到了一个test.Net控制台应用程序中,并要求客户在服务器上运行它,它运行得很好。测试应用程序还获得了所有可用的类别,“进程”就是其中之一。我看到很多计数器都是本地化的。我还让顾客跑了

    lodctr /R
    

    以防性能计数器库出现混乱。这没用。他必须在syswow64文件夹中运行这个命令,否则它将失败。

    当客户运行测试应用程序时,他以管理员身份登录到windows。Windows服务正在以本地系统帐户运行。

    你知道为什么会失败吗?

    在服务的“登录”选项卡上设置本地管理员没有帮助

    0 回复  |  直到 7 年前