Beispiel #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();
                }
            }
        }
        /// <devdoc>
        ///     Frees all the resources allocated for all performance
        ///     counters, frees File Mapping used by extensible counters,
        ///     unloads dll's used to read counters.
        /// </devdoc>
        public static void CloseSharedResources()
        {
            PerformanceCounterPermission permission = new PerformanceCounterPermission(PerformanceCounterPermissionAccess.Read, ".", "*");

            permission.Demand();
            PerformanceCounterLib.CloseAllLibraries();
        }
        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();
                }
            }
        }
Beispiel #4
0
 public static void CloseSharedResources()
 {
     new PerformanceCounterPermission(PerformanceCounterPermissionAccess.Browse, ".", "*").Demand();
     PerformanceCounterLib.CloseAllLibraries();
 }
 /// <summary>
 ///     Frees all the resources allocated for all performance
 ///     counters, frees File Mapping used by extensible counters,
 ///     unloads dll's used to read counters.
 /// </summary>
 public static void CloseSharedResources()
 {
     PerformanceCounterLib.CloseAllLibraries();
 }