コード例 #1
0
        /// <summary>
        ///     Removes the counter (category) from the system
        /// </summary>
        public static void Delete(string categoryName)
        {
            CheckValidCategory(categoryName);
            string machineName = ".";

            categoryName = categoryName.ToLowerInvariant();

            Mutex mutex = null;

            try
            {
                NetFrameworkUtils.EnterMutex(PerfMutexName, ref mutex);
                if (!PerformanceCounterLib.IsCustomCategory(machineName, categoryName))
                {
                    throw new InvalidOperationException(SR.CantDeleteCategory);
                }

                SharedPerformanceCounter.RemoveAllInstances(categoryName);

                PerformanceCounterLib.UnregisterCategory(categoryName);
                PerformanceCounterLib.CloseAllLibraries();
            }
            finally
            {
                if (mutex != null)
                {
                    mutex.ReleaseMutex();
                    mutex.Close();
                }
            }
        }
        public static void Delete(string categoryName)
        {
            CheckValidCategory(categoryName);
            string machineName = ".";

            new PerformanceCounterPermission(PerformanceCounterPermissionAccess.Administer, machineName, categoryName).Demand();
            SharedUtils.CheckNtEnvironment();
            categoryName = categoryName.ToLower(CultureInfo.InvariantCulture);
            Mutex mutex = null;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                SharedUtils.EnterMutex("netfxperf.1.0", ref mutex);
                if (!PerformanceCounterLib.IsCustomCategory(machineName, categoryName))
                {
                    throw new InvalidOperationException(SR.GetString("CantDeleteCategory"));
                }
                SharedPerformanceCounter.RemoveAllInstances(categoryName);
                PerformanceCounterLib.UnregisterCategory(categoryName);
                PerformanceCounterLib.CloseAllLibraries();
            }
            finally
            {
                if (mutex != null)
                {
                    mutex.ReleaseMutex();
                    mutex.Close();
                }
            }
        }
コード例 #3
0
 internal unsafe static void RemoveAllInstances(string categoryName) {
     SharedPerformanceCounter spc = new SharedPerformanceCounter(categoryName, null, null);
     spc.RemoveAllInstances();
     RemoveCategoryData(categoryName);
 }