C#的PerformanceCounter设置计数器的原始值 [英] c# performanceCounter setting raw value of counter

查看:565
本文介绍了C#的PerformanceCounter设置计数器的原始值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想System.Diagnostic的C#的PerformanceCounter图书馆部分。当使用设置计数器的原始值



众长RawValue {设置;得到; }



我经过Rawalue为0。但是我注意到,计数器的最大值重置为一个非常大的数字。计数器以前的值为2



有人能帮助我,并指出任何错误,我可能会做,这里是我的代码



 使用(CTR的PerformanceCounter新= 
的PerformanceCounter(Settings.Instance.SetSourceAppliacationName,counter.ToString(),FALSE))
{
如果(incrementCounter)
{
ctr.IncrementBy(值);
}
,否则
{
ctr.RawValue =价值;
}
}


解决方案

我不要以为你真的犯了一个错误



最大值不是本身的PerformanceCounter的一个特征;它是监控工具(像的PerfMon)的一部分。使用PerformanceCounter类,则不能设置它。



您可能想要做的一件事是你的应用程序前将RawValue设置为零开始尝试应用有用的数据进入它。这可能会非常棘手,如果你有使用一个单实例类(PerformanceCounterCategoryType.SingleInstance),或相同的实例名称(如实例名称)PerformanceCounterCategoryType.MultiInstance多个应用程序。



非常高的数量可能不同于用于存储性能计数器变量的存储器的未初始化块只是一些随机数。由于多个应用程序可能会试图通过实例化一个新的PerformanceCounter对象访问正在进行的性能计数器,该实例化过程不会自动将值设置为零,由设计。


I am trying to c# PerformanceCounter Library part of System.Diagnostic. While setting the raw value of the counter using

public long RawValue { set; get; }

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

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;
    }
}

解决方案

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.

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.

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.

这篇关于C#的PerformanceCounter设置计数器的原始值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆