Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何向已创建的类别添加性能计数器_C#_.net_Performancecounter - Fatal编程技术网

C# 如何向已创建的类别添加性能计数器

C# 如何向已创建的类别添加性能计数器,c#,.net,performancecounter,C#,.net,Performancecounter,我创建了一个PerformanceCounter类别,如下所示 var category = PerformanceCounterCategory.Create("MyCat", "Cat Help", PerformanceCounterCategoryType.SingleInstance, "MyCounter", "Counter Help); 如何向类别添加新计数器以监视其他项目? 我找不到它的api。不久前我对此进行了研究,似乎不可能将计数器添加到现有类别中,您需要做什么才

我创建了一个PerformanceCounter类别,如下所示

var category = PerformanceCounterCategory.Create("MyCat", "Cat Help",
    PerformanceCounterCategoryType.SingleInstance, "MyCounter", "Counter Help);
如何向类别添加新计数器以监视其他项目?

我找不到它的api。

不久前我对此进行了研究,似乎不可能将计数器添加到现有类别中,您需要做什么才能通过添加新计数器来重新创建相同的类别。

谢谢,当我早上启动我的工作笔记本电脑时,我会尝试这样做。首先,使用所有计数器及其类型设置您的计数器类别,如下var lCounters=new CounterCreationDataCollection();添加(新的计数器创建数据(LConterName、LouInterHelp、LConterType));创建(pCategory、lCategoryHelp、PerformanceCounterCategoryType.SingleInstance、lCounters);然后,当您需要计数器实例时,请检查类别/计数器是否存在,然后执行以下操作。。。。var lCounter=新的性能计数器(pCategory、pCounterName、false);lCounter.MachineName=“.”;希望这有帮助。答案描述了如何在删除和重新创建类别+1之前保留计数器。请使用
PerformanceCounterCategory。删除
,然后是
PerformanceCounterCategory。创建
PerformanceCounter lCounter = new PerformanceCounter(Category, CounterName, 
                                                     false);
lCounter.MachineName = ".";