【发布时间】:2015-04-22 06:58:39
【问题描述】:
我在 C# 中创建了一个性能计数器。但是,在为其分配值时,我希望该值是 float 而不是 long,但我似乎不知道该怎么做。有人可以帮忙吗?
我使用的代码来自Counter of type RateOfCountsPerSecond32 always shows 0:
public static void Test()
{
var ccdc = new CounterCreationDataCollection();
// Add the counter.
const string counterName = "RateOfCountsPerSecond64Sample";
var rateOfCounts64 = new CounterCreationData
{
CounterType = PerformanceCounterType.RateOfCountsPerSecond64,
CounterName = counterName
};
ccdc.Add(rateOfCounts64);
// Create the category.
const string categoryName = "RateOfCountsPerSecond64SampleCategory";
if (PerformanceCounterCategory.Exists(categoryName))
PerformanceCounterCategory.Delete(categoryName);
PerformanceCounterCategory.Create(categoryName, "",
PerformanceCounterCategoryType.SingleInstance, ccdc);
// create the counter
var pc = new PerformanceCounter(categoryName, counterName, false);
pc.RawValue = 1000; // <-- want to assign a float value here
}
有人可以帮忙吗?
【问题讨论】:
-
RawValue 是一个长属性,那么为什么要将浮点值分配给长属性?
标签: c# performancecounter