여기서 뭔가 잘못하고있을 것입니다. 다음과 같이 사용자 지정 성능 카운터를 만듭니다.성능 카운터가 변경되지 않는 이유는 무엇입니까?
string counterCategory = "Test Category";
string counterName = "Test Counter";
if (!PerformanceCounterCategory.Exists(counterCategory))
{
Console.WriteLine("Creating Counters");
CounterCreationDataCollection counterCreationDataCollection =
new CounterCreationDataCollection();
counterCreationDataCollection.Add(
new CounterCreationData(counterName,
"Description",
PerformanceCounterType.NumberOfItems32)
);
PerformanceCounterCategory.Create(counterCategory,
"My category description/Help",
PerformanceCounterCategoryType.SingleInstance,
counterCreationDataCollection);
}
성능 카운터에서 카운터 범주와 카운터를 만들고 볼 수 있습니다.
내가 그때 앉아
PerformanceCounter myCounter =
new PerformanceCounter(counterCategory, counterName, false);
for (int i = 0; i < 10; i++)
{
Console.WriteLine("Setting to "+i);
myCounter.RawValue = i;
Thread.Sleep(200);
}
myCounter.Close();
그러나 카운터의 값을 변경하려고 및 성능 모니터 아무것도에서 카운터를 보는 일이, 값은 변경되지 않습니다.
그래서 내가 뭘 잘못하고 있니?
nextValue() 또는 rawValue()에 대한 호출을 추가하면 예상대로 그 값이 반환되지만 Windows 성능 모니터에는 여전히 평행선이 표시됩니다.
for (int i = 0; i < 10; i++)
{
Console.WriteLine("Setting to "+i);
myCounter.IncrementValue()
Console.WriteLine("Next Value = "+myCounter.RawValue());
Thread.Sleep(200);
}
편집 : 내가 성능 모니터를 닫고, 카운터를 삭제하지 않고 다시 열 경우 그 갑자기 새로운 값이의 실현 것으로 나타났습니다. 따라서 값이 설정되고 지속되지만 성능 모니터에서는 변경 내용을 볼 수 없습니다.
제 경우에는 재부팅하십시오. –