I have added performance custom counters to my application to
whether the no of times the operation takes place or not .
But now I want to unregister it .
Is it possible to unregister it remove it .
I have used this counters in C#.
The class which creates a performance category and
adds counters to it .
using System;
using System.Diagnostics;
namespace GroupChatLibrarySamples
{
///<summary>
///Helper class to demonstrate the setup of performance counters.
///</summary>
public class PerformanceCounterHelper
{
//Total number of tests executed
private PerformanceCounter _TotalFiles = null;
/// <summary>
/// Constructor
/// </summary>
public PerformanceCounterHelper()
{
// Set up the performance counter(s)
if (!PerformanceCounterCategory.Exists("Total_Files","."))
{
//Create the collection container
CounterCreationDataCollection counters = new CounterCreationDataCollection();
////Create counter #1 and add it to the collection
CounterCreationData tests = new CounterCreationData();
tests.CounterName = "Total_Files_Sent";
tests.CounterHelp = "Total number of Files Sent";
tests.CounterType = PerformanceCounterType.NumberOfItems32;
counters.Add(tests);
//Create the category and all of the counters.
PerformanceCounterCategory.Create("Total_Files", "Performance Counter for checking no of files sent", counters);
}
try
{
_TotalFiles = new PerformanceCounter();
_TotalFiles.CategoryName = "Total_Files";
_TotalFiles.CounterName = "Total_Files_Sent";
_TotalFiles.MachineName = ".";
_TotalFiles.ReadOnly = false;
}
catch (Exception e)
{
Console.WriteLine(" {0} \n", e.StackTrace);
}
}
public void IncrementCounters()
{
_TotalFiles.Increment();
}
}
}
The code where counter is incremented :
private void BeginSendFilesFinished(IAsyncResult ar)
{
currentOperation.End("BeginSendFilesFinished", () => session.EndUploadFile(ar));
Console.WriteLine(" File Count : {0} \n", listoffiles.Count);
if(sentFiles < (listoffiles.Count-1))
{
sentFiles++;
string SampleFile = listoffiles[sentFiles].ToString();
FileInfo filetoupload = new FileInfo(SampleFile);
ChatRoomFileUploadJob uploadfilejob = new ChatRoomFileUploadJob(filetoupload);
counterHelper.IncrementCounters();
currentOperation.Begin(string.Format("Send Files: # {0}", sentFiles), () => session.BeginUploadFile(uploadfilejob, BeginSendFilesFinished, null));
}
else
{
Log("Leave ChatRoom:");
// After sending 10 chat msgs, leave the chat room (and rejoin).
currentOperation.Begin("Leave ChatRoom:", () => session.BeginLeave(BeginLeaveChatRoomFinished, null));
}
}
Thanks & Regards,
Tazim.
This might be too obvious, but given that you’re trying to do the opposite of the PerformanceCounterCategory.Create action (I think), have you looked at using PerformanceCounterCategory.Delete? According to the documentation it: