繁体   English   中英

取消注册性能计数器

[英]unregistering a performance counters

我已经在我的应用程序中添加了性能自定义计数器,以确定操作是否发生。

但现在我想取消注册它。 是否可以取消注册将其删除。

我在C#中使用过这个计数器。

创建性能类别并向其添加计数器的类。

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();

        }
    }
}

计数器递增的代码:

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

谢谢和问候,Tazim。

这可能太明显了,但考虑到你试图与PerformanceCounterCategory.Create动作相反(我认为),你有没有看过使用PerformanceCounterCategory.Delete 根据文件它:

从本地计算机中删除类别及其关联的计数器

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM