PerformanceCounterCategory.MachineName Property
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets or sets the name of the computer on which this category exists.
public:
property System::String ^ MachineName { System::String ^ get(); void set(System::String ^ value); };
public string MachineName { get; set; }
member this.MachineName : string with get, set
Public Property MachineName As String
The name of the computer on which the performance counter category and its associated counters exist.
The MachineName syntax is invalid.
The following code example creates a PerformanceCounterCategory with the PerformanceCounterCategory() constructor. It prompts the user for the PerformanceCounterCategory and the computer names, then sets the CategoryName and MachineName properties from the entered values. It then displays the values of the CategoryName, MachineName, and CategoryHelp properties, or it displays an error message if the PerformanceCounterCategory cannot be accessed.
public static void Main(string[] args)
{
string categoryName = "";
string machineName = "";
PerformanceCounterCategory pcc = new PerformanceCounterCategory();
// Prompt for fields and set the corresponding properties.
while (categoryName.Length==0)
{
Console.Write("Please enter a non-blank category name: ");
categoryName = Console.ReadLine().Trim();
if (categoryName.Length>0)
{
pcc.CategoryName = categoryName;
}
}
while (machineName.Length==0)
{
Console.Write("Enter a non-blank computer name ['.' for local]: ");
machineName = Console.ReadLine().Trim();
if (machineName.Length>0)
{
pcc.MachineName = machineName;
}
}
// Display the properties of the PerformanceCounterCategory object.
try
{
Console.WriteLine(" Category: {0}", pcc.CategoryName);
Console.WriteLine(" Computer: {0}", pcc.MachineName);
Console.WriteLine(" Help text: {0}", pcc.CategoryHelp);
}
catch(Exception ex)
{
Console.WriteLine("Error getting the properties of the " +
"PerformanceCounterCategory object:");
Console.WriteLine(ex.Message);
}
}
Sub Main(ByVal args() As String)
Dim categoryName As String = ""
Dim machineName As String = ""
Dim pcc As New PerformanceCounterCategory
' Prompt for fields and set the corresponding properties.
While categoryName.Length = 0
Console.Write("Please enter a non-blank category name: ")
categoryName = Console.ReadLine().Trim
If categoryName.Length > 0 Then
pcc.CategoryName = categoryName
End If
End While
While machineName.Length = 0
Console.Write( _
"Enter a non-blank computer name ['.' for local]: ")
machineName = Console.ReadLine().Trim
If machineName.Length > 0 Then
pcc.MachineName = machineName
End If
End While
' Display the properties of the PerformanceCounterCategory object.
Try
Console.WriteLine(" Category: {0}", pcc.CategoryName)
Console.WriteLine(" Computer: {0}", pcc.MachineName)
Console.WriteLine(" Help text: {0}", pcc.CategoryHelp)
Catch ex As Exception
Console.WriteLine("Error getting the properties of the " & _
"PerformanceCounterCategory object:")
Console.WriteLine(ex.Message)
End Try
End Sub
Product | Versions |
---|---|
.NET | 8 (package-provided), 9 (package-provided) |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1 |
.NET Standard | 2.0 (package-provided) |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: