PerformanceCounterInstaller 类

指定 PerformanceCounter 组件的安装程序。

**命名空间:**System.Diagnostics
**程序集:**System.Configuration.Install(在 system.configuration.install.dll 中)

语法

声明
Public Class PerformanceCounterInstaller
    Inherits ComponentInstaller
用法
Dim instance As PerformanceCounterInstaller
public class PerformanceCounterInstaller : ComponentInstaller
public ref class PerformanceCounterInstaller : public ComponentInstaller
public class PerformanceCounterInstaller extends ComponentInstaller
public class PerformanceCounterInstaller extends ComponentInstaller

备注

下面的信息会有助于在应用程序启动时安装性能计数器时提高性能。随 .NET Framework 2.0 版一起安装的性能计数器类别使用单独的共享内存,每个性能计数器类别都拥有自己的内存。使用一个值(如当前默认值 131072)创建一个 DWORD 注册表项 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\<category name>\Performance\FileMappingSize 可指定单独的共享内存的大小。如果该注册表项不存在,则使用 machine.config 文件中指定的 performanceCounters 元素的 fileMappingSize 属性值,这样会增加配置文件处理的开销。使用该注册表项可以实现应用程序启动时的性能改进。

示例

Imports System
Imports System.Configuration.Install
Imports System.Diagnostics
Imports System.ComponentModel

<RunInstaller(True)>  _
Public Class MyPerformanceCounterInstaller
   Inherits Installer
   Public Sub New()
      Try
         ' Create an instance of 'PerformanceCounterInstaller'.
         Dim myPerformanceCounterInstaller As New PerformanceCounterInstaller()
         ' Set the 'CategoryName' for performance counter.
         myPerformanceCounterInstaller.CategoryName = "MyPerformanceCounter"
         Dim myCounterCreation As New CounterCreationData()
         myCounterCreation.CounterName = "MyCounter"
         myCounterCreation.CounterHelp = "Counter Help"
         ' Add a counter to collection of  myPerformanceCounterInstaller.
         myPerformanceCounterInstaller.Counters.Add(myCounterCreation)
         Installers.Add(myPerformanceCounterInstaller)
      Catch e As Exception
         Console.WriteLine("Error occured :" + e.Message)
      End Try
   End Sub 'New
   Public Shared Sub Main()
   End Sub 'Main
End Class 'MyPerformanceCounterInstaller
using System;
using System.Configuration.Install;
using System.Diagnostics;
using System.ComponentModel;

[RunInstaller(true)]
public class MyPerformanceCounterInstaller: Installer
{
   public MyPerformanceCounterInstaller()
   {
      try
      {
         // Create an instance of 'PerformanceCounterInstaller'.
         PerformanceCounterInstaller myPerformanceCounterInstaller =
            new PerformanceCounterInstaller();
         // Set the 'CategoryName' for performance counter.
         myPerformanceCounterInstaller.CategoryName =
            "MyPerformanceCounter";
         CounterCreationData myCounterCreation = new CounterCreationData();
         myCounterCreation.CounterName = "MyCounter";
         myCounterCreation.CounterHelp = "Counter Help";
         // Add a counter to collection of  myPerformanceCounterInstaller.
         myPerformanceCounterInstaller.Counters.Add(myCounterCreation);
         Installers.Add(myPerformanceCounterInstaller);
      }
      catch(Exception e)
      {
         Console.WriteLine("Error occured :"+e.Message);
      }
   }
   public static void Main()
   {
   }
}
#using <System.dll>
#using <System.Configuration.Install.dll>

using namespace System;
using namespace System::Configuration::Install;
using namespace System::Diagnostics;
using namespace System::ComponentModel;

[RunInstaller(true)]
ref class MyPerformanceCounterInstaller: public Installer
{
public:
   MyPerformanceCounterInstaller()
   {
      try
      {
         // Create an instance of 'PerformanceCounterInstaller'.
         PerformanceCounterInstaller^ myPerformanceCounterInstaller =
            gcnew PerformanceCounterInstaller;
         // Set the 'CategoryName' for performance counter.
         myPerformanceCounterInstaller->CategoryName =
            "MyPerformanceCounter";
         CounterCreationData^ myCounterCreation = gcnew CounterCreationData;
         myCounterCreation->CounterName = "MyCounter";
         myCounterCreation->CounterHelp = "Counter Help";
         // Add a counter to collection of  myPerformanceCounterInstaller.
         myPerformanceCounterInstaller->Counters->Add( myCounterCreation );
         Installers->Add( myPerformanceCounterInstaller );
      }
      catch ( Exception^ e ) 
      {
         Console::WriteLine( "Error occured :{0}", e->Message );
      }
   }
};
import System.*;
import System.Configuration.Install.*;
import System.Diagnostics.*;
import System.ComponentModel.*;

/** @attribute RunInstaller(true)
 */
public class MyPerformanceCounterInstaller extends Installer
{
    public MyPerformanceCounterInstaller()
    {
        try {
            // Create an instance of 'PerformanceCounterInstaller'.
            PerformanceCounterInstaller myPerformanceCounterInstaller =
                new PerformanceCounterInstaller();
            // Set the 'CategoryName' for performance counter.
            myPerformanceCounterInstaller.set_CategoryName(
                "MyPerformanceCounter");
            CounterCreationData myCounterCreation = 
                new CounterCreationData();
            myCounterCreation.set_CounterName("MyCounter");
            myCounterCreation.set_CounterHelp("Counter Help");
            // Add a counter to collection of  myPerformanceCounterInstaller.
            myPerformanceCounterInstaller.get_Counters().Add(myCounterCreation);
            InstallerCollection installers = null;
            installers.Add(myPerformanceCounterInstaller);
        }
        catch (System.Exception e) {
            Console.WriteLine("Error occured :" + e.get_Message());
        }
    } //MyPerformanceCounterInstaller

    public static void main(String[] args)
    {
    } //main
} //MyPerformanceCounterInstaller

继承层次结构

System.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
       System.Configuration.Install.Installer
         System.Configuration.Install.ComponentInstaller
          System.Diagnostics.PerformanceCounterInstaller

线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

平台

Windows 98、Windows 2000 SP4、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

PerformanceCounterInstaller 成员
System.Diagnostics 命名空间