Hi i create many PerformanceCounter My problem is when i set value of one counter it change in all other counters this is my code:
public class PerformanceCounterHelper
{
private const string COUNTER_STILL_ALIVE = "Nb secondes depuis dernière activité";
private const string COUNTER_STILL_ALIVE_HELP = "Nombre de secondes depuis le dernier signe de vie";
private const string COUNTER_MESSAGE_NUMBER = "Nb messages traités";
private const string COUNTER_MESSAGE_NUMBER_HELP = "Nombre de messages traités par le dispatcher";
private const string COUNTER_MESSAGE_ERROR = "Nb messages en erreur";
private const string COUNTER_MESSAGE_ERROR_HELP = "Nombre de messages en erreur";
private PerformanceCounter stillAliveCounter;
private PerformanceCounter messageNumberCounter;
private PerformanceCounter messageErrorNumberCounter;
public PerformanceCounterHelper(string categoryName)
{
stillAliveCounter = new PerformanceCounter(categoryName, COUNTER_STILL_ALIVE, false);
messageNumberCounter = new PerformanceCounter(categoryName, COUNTER_MESSAGE_NUMBER, false);
messageErrorNumberCounter = new PerformanceCounter(categoryName, COUNTER_MESSAGE_ERROR, false);
//DonnerSigneDeVie();
messageNumberCounter.RawValue = 0;
messageErrorNumberCounter.RawValue = 0;
}
public void DonnerSigneDeVie() {stillAliveCounter.RawValue = Stopwatch.GetTimestamp();}
public void IncrementerNombreMessagesTraites()
{
messageNumberCounter.RawValue += 1;
}
public void IncrementerNombreMessagesEnErreur()
{
messageErrorNumberCounter.RawValue += 1;
}
public PerformanceCounterHelper()
{ }
In the end all counters values have values "3"
I can't see your class PerformanceCounter, but I think there is a static variable in it, that holds the RawValue
!?
Remove the static
from the variable and it should work.
For more feedback, please show us the class.
How to edit a question: