1
我想在應用程序中使用.NET性能計數器。這裏是代碼:使用.net性能計數器時崩潰
if (!PerformanceCounterCategory.Exists("Processor"))
{
CounterCreationDataCollection CCDC = new CounterCreationDataCollection();
// Add the counter.
CounterCreationData NOI64 = new CounterCreationData();
NOI64.CounterType = PerformanceCounterType.NumberOfItems64;
NOI64.CounterName = "%Processor Time";
CCDC.Add(NOI64);
// Create the category.
PerformanceCounterCategory.Create("Processor", "", PerformanceCounterCategoryType.SingleInstance, CCDC);
}
PerformanceCounter PC = new PerformanceCounter("Processor", "%Processor Time", false);
PC.RawValue = 0;
當我執行這個代碼,我在下面
提到的類型的未處理的異常
PerformanceCounter PC = new PerformanceCounter("Processor", "%Processor Time", false);
得到崩潰 'System.InvalidOperationException' 發生在System.dll中附加信息:請求的性能計數器不是自定義計數器,它必須初始化爲ReadOnly。
我試圖using lodctr
命令也不過它在The requested Performance Counter is not a custom counter, it has to be initialized as ReadOnly
awww ...我真的忽略了這個參數,並且在設置性能計數器方面做了很多故障排除。謝謝你的幫助... – Nipun