检索其他语言的PerformanceCounterCategories

本文关键字:PerformanceCounterCategories 语言 其他 检索 | 更新日期: 2023-09-27 18:21:40

当我显示所有PerformanceCounterCategories的列表时,我会收到一个荷兰语列表,因为这是我的操作系统语言。可以检索英文列表吗?

private static void Main(string[] args) {
        var cats = new List<PerformanceCounterCategory>(PerformanceCounterCategory.GetCategories());
        foreach (var name in cats.OrderBy(x => x.CategoryName)) {
            Console.WriteLine(name.CategoryName);
        }
        Console.ReadKey();
}

编辑:除此之外,是否有一个可能的类别及其计数器的在线列表?我一直在到处寻找,还没有偶然发现一个真正的清单。

到目前为止,我唯一找到的就是这篇文章,它引出了一个类别列表。然而,由于它没有提供任何关于类别本身的信息,我已经收到一个异常,说明当我使用时,该类别不存在

var temp = new PerformanceCounterCategory("IP");
Console.WriteLine(temp.CategoryHelp);

检索其他语言的PerformanceCounterCategories

由于它表面上使用Thread.CurrentCulture,您无法指定检索所有内容的语言。安装英语语言包并更改您的CurrentCulture可能是可行的,但我没有遵循这种可能性。

相反,一个拥有英语操作系统的人向我提供了他上面代码的结果,我将使用它作为硬编码英语类别的参考,而不是荷兰语。英语对我来说似乎很好用,所以我猜它在每台机器上都是标准的。

我还没有找到关于这些类别的实际文档,但通过使用常识,我能够将这些technet文章与上面链接的列表中显示的适当类别相结合。

确保其工作的示例:

 var temp = new PerformanceCounter("IPv4", "Datagrams/sec");
 console.WriteLine(temp.CategoryName);
 while (true) {
      float total = 0;
      for (var i = 0; i < 10; i++) {
              total += temp.NextValue();
      }
      Console.WriteLine(total);
      Thread.Sleep(1000);
 }

为我提供了稳定的数据流,尽管Technet上的文档只将类别指定为"IP对象",而没有区分"IPv4"answers"IPv6"。

如果有人真的找到了解决原始问题的可靠方法(用英语显示所有类别,尽管主机系统有偏好),只需将其添加为答案,我会接受。

编辑:改变CurrentCulture:的解决方案

System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
            var cats = new List<PerformanceCounterCategory>(PerformanceCounterCategory.GetCategories());
            foreach (var name in cats.OrderBy(x => x.CategoryName)) {
                Console.WriteLine("en-US: " + name.CategoryName);
            }
            System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("nl-NL");
            cats = new List<PerformanceCounterCategory>(PerformanceCounterCategory.GetCategories());
            foreach (var name in cats.OrderBy(x => x.CategoryName)) {
                Console.WriteLine("nl-NL: " + name.CategoryName);
            }
相关文章:
  • 没有找到相关文章