I am trying to c# PerformanceCounter Library part of System.Diagnostic. While setting the raw value of the counter using
我正在尝试使用System.Diagnostic的c#PerformanceCounter Library部分。使用时设置计数器的原始值
public long RawValue { set; get; }
public long RawValue {set;得到; }
I was passing the Rawalue to 0. However I noticed that Maximum value of the counter was reset to a very large number. Previous value of the counter was 2
我正在将Rawalue传递给0.但是我注意到计数器的最大值被重置为非常大的数字。该计数器的先前值为2
Can someone help me out and point out any mistake I might be making, here is my code
有人可以帮助我,并指出我可能犯的任何错误,这是我的代码
using (PerformanceCounter ctr = new
PerformanceCounter(Settings.Instance.SetSourceAppliacationName, counter.ToString(), false))
{
if (incrementCounter)
{
ctr.IncrementBy(value);
}
else
{
ctr.RawValue = value;
}
}
1 个解决方案
#1
I don't think you're really making a mistake.
我不认为你真的犯了错误。
The Maximum value is not a feature of the PerformanceCounter itself; it is a part of the monitoring tool (like PerfMon). You can't set it using the PerformanceCounter class.
最大值不是PerformanceCounter本身的功能;它是监控工具的一部分(如PerfMon)。您无法使用PerformanceCounter类进行设置。
One thing you might want to do is to set the RawValue to zero before your application starts trying to apply useful data into it. This can be tricky if you have multiple applications using either a single instance category (PerformanceCounterCategoryType.SingleInstance), or the same instance name (like a "total" instance name) for PerformanceCounterCategoryType.MultiInstance.
您可能想要做的一件事是在应用程序开始尝试将有用数据应用到其中之前将RawValue设置为零。如果您有多个应用程序使用单个实例类别(PerformanceCounterCategoryType.SingleInstance),或者使用相同的实例名称(如“总”实例名称),那么这对于PerformanceCounterCategoryType.MultiInstance来说可能会非常棘手。
The very high number is likely just some random number from an uninitialized block of memory that is used to store the performance counter variable. Because multiple applications might try to access an ongoing performance counter by instantiating a new PerformanceCounter object, that instantiation process does not automatically set the value to zero, by design.
非常高的数字可能只是来自未初始化的内存块的一些随机数,用于存储性能计数器变量。由于多个应用程序可能尝试通过实例化新的PerformanceCounter对象来访问正在进行的性能计数器,因此该实例化过程不会按设计自动将该值设置为零。
#1
I don't think you're really making a mistake.
我不认为你真的犯了错误。
The Maximum value is not a feature of the PerformanceCounter itself; it is a part of the monitoring tool (like PerfMon). You can't set it using the PerformanceCounter class.
最大值不是PerformanceCounter本身的功能;它是监控工具的一部分(如PerfMon)。您无法使用PerformanceCounter类进行设置。
One thing you might want to do is to set the RawValue to zero before your application starts trying to apply useful data into it. This can be tricky if you have multiple applications using either a single instance category (PerformanceCounterCategoryType.SingleInstance), or the same instance name (like a "total" instance name) for PerformanceCounterCategoryType.MultiInstance.
您可能想要做的一件事是在应用程序开始尝试将有用数据应用到其中之前将RawValue设置为零。如果您有多个应用程序使用单个实例类别(PerformanceCounterCategoryType.SingleInstance),或者使用相同的实例名称(如“总”实例名称),那么这对于PerformanceCounterCategoryType.MultiInstance来说可能会非常棘手。
The very high number is likely just some random number from an uninitialized block of memory that is used to store the performance counter variable. Because multiple applications might try to access an ongoing performance counter by instantiating a new PerformanceCounter object, that instantiation process does not automatically set the value to zero, by design.
非常高的数字可能只是来自未初始化的内存块的一些随机数,用于存储性能计数器变量。由于多个应用程序可能尝试通过实例化新的PerformanceCounter对象来访问正在进行的性能计数器,因此该实例化过程不会按设计自动将该值设置为零。