Export (0) Print
Expand All

PerformanceCounterCategory.Exists Method

Determines whether the category is registered on the system.

Overload List

Determines whether the category is registered on the local computer.

[Visual Basic] Overloads Public Shared Function Exists(String) As Boolean
[C#] public static bool Exists(string);
[C++] public: static bool Exists(String*);
[JScript] public static function Exists(String) : Boolean;

Determines whether the category is registered on the specified computer.

[Visual Basic] Overloads Public Shared Function Exists(String, String) As Boolean
[C#] public static bool Exists(string, string);
[C++] public: static bool Exists(String*, String*);
[JScript] public static function Exists(String, String) : Boolean;


[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of Exists. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
If Not PerformanceCounterCategory.Exists("Orders") Then        
    Dim milk As New CounterCreationData()
    milk.CounterName = "milk"
    milk.CounterType = PerformanceCounterType.NumberOfItems32
    Dim milkPerSecond As New CounterCreationData()
    milkPerSecond.CounterName = "milk orders/second"
    milkPerSecond.CounterType = PerformanceCounterType.RateOfCountsPerSecond32
    Dim ccds As New CounterCreationDataCollection()
    PerformanceCounterCategory.Create("Orders", "Number of processed orders", ccds)    
End If

if(!PerformanceCounterCategory.Exists("Orders")) {          
    CounterCreationData milk = new CounterCreationData();
    milk.CounterName = "milk";
    milk.CounterType = PerformanceCounterType.NumberOfItems32;
    CounterCreationData milkPerSecond = new CounterCreationData();
    milkPerSecond.CounterName = "milk orders/second";
    milkPerSecond.CounterType = PerformanceCounterType.RateOfCountsPerSecond32;
    CounterCreationDataCollection ccds = new CounterCreationDataCollection();
    PerformanceCounterCategory.Create("Orders","Number of processed orders",ccds);           

if(!PerformanceCounterCategory::Exists(S"Orders")) {          
    CounterCreationData* milk = new CounterCreationData();
    milk->CounterName = S"milk";
    milk->CounterType = PerformanceCounterType::NumberOfItems32;

    CounterCreationData* milkPerSecond = new CounterCreationData();
    milkPerSecond->CounterName = S"milk orders/second";
    milkPerSecond->CounterType = PerformanceCounterType::RateOfCountsPerSecond32;

    CounterCreationDataCollection* ccds = new CounterCreationDataCollection();

    PerformanceCounterCategory::Create(S"Orders",S"Number of processed orders",ccds);           

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

PerformanceCounterCategory Class | PerformanceCounterCategory Members | System.Diagnostics Namespace

© 2014 Microsoft