Aracılığıyla paylaş


PerformanceCounterCategory.CounterExists Yöntem

Tanım

Belirtilen sayacın belirli bir kategoriye kaydedilip kaydedilmediğini belirler.

Aşırı Yüklemeler

CounterExists(String)

Belirtilen sayacın ve MachineName özellikleriyle CategoryName gösterilen bu kategoriye kaydedilip kaydedilmediğini belirler.

CounterExists(String, String)

Belirtilen sayacın yerel bilgisayarda belirtilen kategoriye kaydedilip kaydedilmediğini belirler.

CounterExists(String, String, String)

Belirtilen sayacın uzak bilgisayarda belirtilen kategoriye kaydedilip kaydedilmediğini belirler.

CounterExists(String)

Kaynak:
PerformanceCounterCategory.cs
Kaynak:
PerformanceCounterCategory.cs
Kaynak:
PerformanceCounterCategory.cs

Belirtilen sayacın ve MachineName özellikleriyle CategoryName gösterilen bu kategoriye kaydedilip kaydedilmediğini belirler.

public:
 bool CounterExists(System::String ^ counterName);
public bool CounterExists (string counterName);
member this.CounterExists : string -> bool
Public Function CounterExists (counterName As String) As Boolean

Parametreler

counterName
String

Aranacak performans sayacının adı.

Döndürülenler

truesayaç ve özellikleri tarafından CategoryName belirtilen kategoriye kayıtlıysa; aksi takdirde , false.MachineName

Özel durumlar

şeklindedir counterNamenull.

CategoryName özelliği ayarlanmadı.

Temel alınan sistem API'sine yapılan çağrı başarısız oldu.

Yönetici ayrıcalıkları olmadan yürütülen kod bir performans sayacını okumaya çalıştı.

Örnekler

Aşağıdaki kod örneği, bir PerformanceCounter olup olmadığını belirler. Verilen komut satırından bir kategori adı, sayaç adı ve bilgisayar adı alır. Uygun PerformanceCounterCategorykullanarak bir PerformanceCounterCategory nesnesi oluşturur. Daha sonra belirtilen PerformanceCounter var olup olmadığını belirlemek için yöntemini kullanır CounterExists(String) ve kullanıcıyı bilgilendirmektedir.

public static void Main(string[] args)
{
    string categoryName = "";
    string counterName = "";
    string machineName = "";
    bool objectExists = false;
    PerformanceCounterCategory pcc;

    // Copy the supplied arguments into the local variables.
    try
    {
        categoryName = args[0];
        counterName = args[1];
        machineName = (args[2]=="."? "": args[2]);
    }
    catch(Exception ex)
    {
        // Ignore the exception from non-supplied arguments.
    }

    try
    {
        if (machineName.Length==0)
        {
            pcc = new PerformanceCounterCategory(categoryName);
        }
        else
        {
            pcc = new PerformanceCounterCategory(categoryName, machineName);
        }

        // Check whether the specified counter exists.
        // Use the per-instance overload of CounterExists.
        objectExists = pcc.CounterExists(counterName);
    }
    catch(Exception ex)
    {
        Console.WriteLine("Unable to check for the existence of " +
            "counter \"{0}\" in category \"{1}\" on "+
            (machineName.Length>0? "computer \"{2}\".": "this computer.")+ "\n" +
            ex.Message, counterName, categoryName, machineName);
        return;
    }

    // Tell the user whether the counter exists.
    Console.WriteLine("Counter \"{0}\" " + (objectExists? "exists": "does not exist") +
        " in category \"{1}\" on " + (machineName.Length>0? "computer \"{2}\".": "this computer."),
        counterName, pcc.CategoryName, pcc.MachineName);
}
Sub Main(ByVal args() As String)
    Dim categoryName As String = ""
    Dim counterName As String = ""
    Dim machineName As String = ""
    Dim objectExists As Boolean = False
    Dim pcc As PerformanceCounterCategory

    ' Copy the supplied arguments into the local variables.
    Try
        categoryName = args(0)
        counterName = args(1)
        machineName = IIf(args(2) = ".", "", args(2))
    Catch ex As Exception
        ' Ignore the exception from non-supplied arguments.
    End Try

    Try
        If machineName.Length = 0 Then
            pcc = New PerformanceCounterCategory(categoryName)
        Else
            pcc = New PerformanceCounterCategory(categoryName, machineName)
        End If

        ' Check whether the specified counter exists.
        ' Use the per-instance overload of CounterExists.
        objectExists = pcc.CounterExists(counterName)

    Catch ex As Exception
        Console.WriteLine("Unable to check for the existence of " & _
            "counter ""{0}"" in category ""{1}"" on " & _
            IIf(machineName.Length > 0, _
            "computer ""{2}"".", "this computer.") & vbCrLf & _
            ex.Message, counterName, categoryName, machineName)
        Return
    End Try

    ' Tell the user whether the counter exists.
    Console.WriteLine("Counter ""{0}"" " & _
        IIf(objectExists, "exists", "does not exist") & _
        " in category ""{1}"" on " & _
        IIf(machineName.Length > 0, _
            "computer ""{2}"".", "this computer."), _
        counterName, pcc.CategoryName, pcc.MachineName)
End Sub

Açıklamalar

Bu yöntemi çağırmadan önce özelliğini ayarlamanız CategoryName gerekir. Aksi takdirde, bir özel durum oluşturulur.

Özelliğini ayarlamadıysanız MachineName , bu yöntem yerel bilgisayarı (".") kullanır.

Not

Windows Vista ve sonraki sürümlerde, Windows XP Professional x64 Edition veya Windows Server 2003'te etkileşimli olmayan bir oturumdan performans sayaçlarını okumak için, Performans İzleyicisi Kullanıcıları grubunun üyesi olmanız veya yönetici ayrıcalıklarına sahip olmanız gerekir.

Windows Vista ve sonraki sürümlerde performans sayaçlarına erişmek için ayrıcalıklarınızı yükseltmek zorunda kalmamak için kendinizi Performans İzleyicisi Kullanıcılar grubuna ekleyin.

Windows Vista ve sonraki sürümlerde, Kullanıcı Hesabı Denetimi (UAC) bir kullanıcının ayrıcalıkları belirler. Yerleşik Yöneticiler grubunun bir üyesi iseniz, size iki çalışma zamanı erişim belirteci atanır: Standart kullanıcı erişim belirteci ve yönetici erişim belirteci. Varsayılan olarak, standart kullanıcı rolünde olursunuz. Performans sayaçlarına erişen kodu yürütmek için öncelikle ayrıcalıklarınızı standart kullanıcıdan yöneticiye yükseltmeniz gerekir. Bir uygulamayı başlattığınızda, uygulama simgesine sağ tıklayıp yönetici olarak çalıştırmak istediğinizi belirterek bunu yapabilirsiniz.

Ayrıca bkz.

Şunlara uygulanır

CounterExists(String, String)

Kaynak:
PerformanceCounterCategory.cs
Kaynak:
PerformanceCounterCategory.cs
Kaynak:
PerformanceCounterCategory.cs

Belirtilen sayacın yerel bilgisayarda belirtilen kategoriye kaydedilip kaydedilmediğini belirler.

public:
 static bool CounterExists(System::String ^ counterName, System::String ^ categoryName);
public static bool CounterExists (string counterName, string categoryName);
static member CounterExists : string * string -> bool
Public Shared Function CounterExists (counterName As String, categoryName As String) As Boolean

Parametreler

counterName
String

Aranacak performans sayacının adı.

categoryName
String

Belirtilen performans sayacının ilişkilendirildiği performans sayacı kategorisinin veya performans nesnesinin adı.

Döndürülenler

true, sayaç yerel bilgisayarda belirtilen kategoriye kayıtlıysa; aksi takdirde , false.

Özel durumlar

şeklindedir categoryNamenull.

-veya-

şeklindedir counterNamenull.

categoryName boş bir dizedir ("").

Kategori adı yok.

Temel alınan sistem API'sine yapılan çağrı başarısız oldu.

Yönetici ayrıcalıkları olmadan yürütülen kod bir performans sayacını okumaya çalıştı.

Örnekler

Aşağıdaki kod örneği, bir PerformanceCounter olup olmadığını belirler. Verilen komut satırından bir kategori adı, sayaç adı ve bilgisayar adı alır. Belirtilen PerformanceCounter adın içinde mevcut olup olmadığını belirlemek için yönteminin statik aşırı yüklemelerini CounterExistsPerformanceCounterCategorykullanır. Aşırı yükleme, bir bilgisayar adının sağlanıp sağlanmadığına göre seçilir.

public static void Main(string[] args)
{
    string categoryName = "";
    string counterName = "";
    string machineName = "";
    bool objectExists = false;

    // Copy the supplied arguments into the local variables.
    try
    {
        categoryName = args[0];
        counterName = args[1];
        machineName = args[2]=="."? "": args[2];
    }
    catch(Exception ex)
    {
        // Ignore the exception from non-supplied arguments.
    }

    try
    {
        // Check whether the specified counter exists.
        // Use the static forms of the CounterExists method.
        if (machineName.Length==0)
        {
            objectExists = PerformanceCounterCategory.CounterExists(counterName, categoryName);
        }
        else
        {
            objectExists = PerformanceCounterCategory.CounterExists(counterName, categoryName, machineName);
        }
    }
    catch(Exception ex)
    {
        Console.WriteLine("Unable to check for the existence of " +
            "counter \"{0}\" in category \"{1}\" on " +
            (machineName.Length>0? "computer \"{2}\".": "this computer.") + "\n" +
            ex.Message, counterName, categoryName, machineName);
        return;
    }

    // Tell the user whether the counter exists.
    Console.WriteLine("Counter \"{0}\" "+ (objectExists? "exists": "does not exist") +
        " in category \"{1}\" on " + (machineName.Length>0? "computer \"{2}\".": "this computer."),
        counterName, categoryName, machineName);
}
Sub Main(ByVal args() As String)
    Dim categoryName As String = ""
    Dim counterName As String = ""
    Dim machineName As String = ""
    Dim objectExists As Boolean = False

    ' Copy the supplied arguments into the local variables.
    Try
        categoryName = args(0)
        counterName = args(1)
        machineName = IIf(args(2) = ".", "", args(2))
    Catch ex As Exception
        ' Ignore the exception from non-supplied arguments.
    End Try

    Try
        ' Check whether the specified counter exists.
        ' Use the static forms of the CounterExists method.
        If machineName.Length = 0 Then
            objectExists = PerformanceCounterCategory.CounterExists( _
                counterName, categoryName)
        Else
            objectExists = PerformanceCounterCategory.CounterExists( _
                counterName, categoryName, machineName)
        End If

    Catch ex As Exception
        Console.WriteLine("Unable to check for the existence of " & _
            "counter ""{0}"" in category ""{1}"" on " & _
            IIf(machineName.Length > 0, _
            "computer ""{2}"".", "this computer.") & vbCrLf & _
            ex.Message, counterName, categoryName, machineName)
        Return
    End Try

    ' Tell the user whether the counter exists.
    Console.WriteLine("Counter ""{0}"" " & _
        IIf(objectExists, "exists", "does not exist") & _
        " in category ""{1}"" on " & _
        IIf(machineName.Length > 0, _
            "computer ""{2}"".", "this computer."), _
        counterName, categoryName, machineName)
End Sub

Açıklamalar

Not

Windows Vista ve sonraki sürümlerde, Windows XP Professional x64 Edition veya Windows Server 2003'te etkileşimli olmayan bir oturumdan performans sayaçlarını okumak için, Performans İzleyicisi Kullanıcıları grubunun üyesi olmanız veya yönetici ayrıcalıklarına sahip olmanız gerekir.

Windows Vista ve sonraki sürümlerde performans sayaçlarına erişmek için ayrıcalıklarınızı yükseltmek zorunda kalmamak için kendinizi Performans İzleyicisi Kullanıcılar grubuna ekleyin.

Windows Vista ve sonraki sürümlerde, Kullanıcı Hesabı Denetimi (UAC) bir kullanıcının ayrıcalıkları belirler. Yerleşik Yöneticiler grubunun bir üyesi iseniz, size iki çalışma zamanı erişim belirteci atanır: Standart kullanıcı erişim belirteci ve yönetici erişim belirteci. Varsayılan olarak, standart kullanıcı rolünde olursunuz. Performans sayaçlarına erişen kodu yürütmek için öncelikle ayrıcalıklarınızı standart kullanıcıdan yöneticiye yükseltmeniz gerekir. Bir uygulamayı başlattığınızda, uygulama simgesine sağ tıklayıp yönetici olarak çalıştırmak istediğinizi belirterek bunu yapabilirsiniz.

Ayrıca bkz.

Şunlara uygulanır

CounterExists(String, String, String)

Kaynak:
PerformanceCounterCategory.cs
Kaynak:
PerformanceCounterCategory.cs
Kaynak:
PerformanceCounterCategory.cs

Belirtilen sayacın uzak bilgisayarda belirtilen kategoriye kaydedilip kaydedilmediğini belirler.

public:
 static bool CounterExists(System::String ^ counterName, System::String ^ categoryName, System::String ^ machineName);
public static bool CounterExists (string counterName, string categoryName, string machineName);
static member CounterExists : string * string * string -> bool
Public Shared Function CounterExists (counterName As String, categoryName As String, machineName As String) As Boolean

Parametreler

counterName
String

Aranacak performans sayacının adı.

categoryName
String

Belirtilen performans sayacının ilişkilendirildiği performans sayacı kategorisinin veya performans nesnesinin adı.

machineName
String

Performans sayacı kategorisinin ve ilişkili sayaçlarının bulunduğu bilgisayarın adı.

Döndürülenler

true, sayaç belirtilen bilgisayarda belirtilen kategoriye kayıtlıysa; aksi takdirde , false.

Özel durumlar

şeklindedir categoryNamenull.

-veya-

şeklindedir counterNamenull.

categoryName boş bir dizedir ("").

-veya-

machineName geçersiz.

Kategori adı yok.

Temel alınan sistem API'sine yapılan çağrı başarısız oldu.

Yönetici ayrıcalıkları olmadan yürütülen kod bir performans sayacını okumaya çalıştı.

Örnekler

Aşağıdaki kod örneği, bir PerformanceCounter olup olmadığını belirler. Verilen komut satırından bir kategori adı, sayaç adı ve bilgisayar adı alır. Belirtilen PerformanceCounter adın içinde mevcut olup olmadığını belirlemek için yönteminin statik aşırı yüklemelerini CounterExistsPerformanceCounterCategorykullanır. Aşırı yükleme, bir bilgisayar adının sağlanıp sağlanmadığına göre seçilir.

public static void Main(string[] args)
{
    string categoryName = "";
    string counterName = "";
    string machineName = "";
    bool objectExists = false;

    // Copy the supplied arguments into the local variables.
    try
    {
        categoryName = args[0];
        counterName = args[1];
        machineName = args[2]=="."? "": args[2];
    }
    catch(Exception ex)
    {
        // Ignore the exception from non-supplied arguments.
    }

    try
    {
        // Check whether the specified counter exists.
        // Use the static forms of the CounterExists method.
        if (machineName.Length==0)
        {
            objectExists = PerformanceCounterCategory.CounterExists(counterName, categoryName);
        }
        else
        {
            objectExists = PerformanceCounterCategory.CounterExists(counterName, categoryName, machineName);
        }
    }
    catch(Exception ex)
    {
        Console.WriteLine("Unable to check for the existence of " +
            "counter \"{0}\" in category \"{1}\" on " +
            (machineName.Length>0? "computer \"{2}\".": "this computer.") + "\n" +
            ex.Message, counterName, categoryName, machineName);
        return;
    }

    // Tell the user whether the counter exists.
    Console.WriteLine("Counter \"{0}\" "+ (objectExists? "exists": "does not exist") +
        " in category \"{1}\" on " + (machineName.Length>0? "computer \"{2}\".": "this computer."),
        counterName, categoryName, machineName);
}
Sub Main(ByVal args() As String)
    Dim categoryName As String = ""
    Dim counterName As String = ""
    Dim machineName As String = ""
    Dim objectExists As Boolean = False

    ' Copy the supplied arguments into the local variables.
    Try
        categoryName = args(0)
        counterName = args(1)
        machineName = IIf(args(2) = ".", "", args(2))
    Catch ex As Exception
        ' Ignore the exception from non-supplied arguments.
    End Try

    Try
        ' Check whether the specified counter exists.
        ' Use the static forms of the CounterExists method.
        If machineName.Length = 0 Then
            objectExists = PerformanceCounterCategory.CounterExists( _
                counterName, categoryName)
        Else
            objectExists = PerformanceCounterCategory.CounterExists( _
                counterName, categoryName, machineName)
        End If

    Catch ex As Exception
        Console.WriteLine("Unable to check for the existence of " & _
            "counter ""{0}"" in category ""{1}"" on " & _
            IIf(machineName.Length > 0, _
            "computer ""{2}"".", "this computer.") & vbCrLf & _
            ex.Message, counterName, categoryName, machineName)
        Return
    End Try

    ' Tell the user whether the counter exists.
    Console.WriteLine("Counter ""{0}"" " & _
        IIf(objectExists, "exists", "does not exist") & _
        " in category ""{1}"" on " & _
        IIf(machineName.Length > 0, _
            "computer ""{2}"".", "this computer."), _
        counterName, categoryName, machineName)
End Sub

Açıklamalar

Not

Windows Vista ve sonraki sürümlerde, Windows XP Professional x64 Edition veya Windows Server 2003'te etkileşimli olmayan bir oturumdan performans sayaçlarını okumak için, Performans İzleyicisi Kullanıcıları grubunun üyesi olmanız veya yönetici ayrıcalıklarına sahip olmanız gerekir.

Windows Vista ve sonraki sürümlerde performans sayaçlarına erişmek için ayrıcalıklarınızı yükseltmek zorunda kalmamak için kendinizi Performans İzleyicisi Kullanıcılar grubuna ekleyin.

Windows Vista ve sonraki sürümlerde, Kullanıcı Hesabı Denetimi (UAC) bir kullanıcının ayrıcalıkları belirler. Yerleşik Yöneticiler grubunun bir üyesi iseniz, size iki çalışma zamanı erişim belirteci atanır: Standart kullanıcı erişim belirteci ve yönetici erişim belirteci. Varsayılan olarak, standart kullanıcı rolünde olursunuz. Performans sayaçlarına erişen kodu yürütmek için öncelikle ayrıcalıklarınızı standart kullanıcıdan yöneticiye yükseltmeniz gerekir. Bir uygulamayı başlattığınızda, uygulama simgesine sağ tıklayıp yönetici olarak çalıştırmak istediğinizi belirterek bunu yapabilirsiniz.

Ayrıca bkz.

Şunlara uygulanır