|
-
Oct 18th, 2007, 12:38 PM
#1
Thread Starter
Junior Member
[RESOLVED] [2005] PerformanceCounter & the GetInstanceNames function
After many varying searches on both this forum and the MSDN library I haven't found any examples that explain or provide code to successfully list all the instance names from a PerformanceCounter.
The performance counter I am trying to use works fine on this PC when i choose the InstanceName in design mode, but for distribution I need this to be selectable by the user.
I would greatley appreciate a sample or a link expaining what I need to declare and how to use it to output a list of InstanceNames to a combobox.
For coding simplicity to start with I have left the performancecounter named 'PerformanceCounter1' and the combobox 'ComboBox1'. I know the solution has something to do with the GetInstanceNames command but i don't know where that is or how to use it.
Any and all help will be appreciated
-
Oct 18th, 2007, 02:59 PM
#2
Re: [2005] PerformanceCounter & the GetInstanceNames function
I think I recall doing something similar in this example......?
GetInstanceNames returns an array of strings - you could set your Combobox.DataSouce to it...
-
Oct 18th, 2007, 07:16 PM
#3
Thread Starter
Junior Member
-
Oct 19th, 2007, 02:47 AM
#4
Thread Starter
Junior Member
Re: [RESOLVED] [2005] PerformanceCounter & the GetInstanceNames function
Using the example on http://msdn2.microsoft.com/en-us/lib...ancenames.aspx I have gotten the following working by repopulating the dropdown list on demand:
Code:
Private Sub ComboBox1_DropDown(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.DropDown
'original code URL: http://msdn2.microsoft.com/en-us/lib...ancenames.aspx
'thanks to Merrion for pointing me to the relevant links
'code made to work in a method I understand by myself (Liam Parrish) on 18/10/2007
Dim pcc As PerformanceCounterCategory
Dim instances() As String
'machineName "." refers to the local machine
Dim machineName As String = "."
'this can be reset in code later or made a public string so this could be used to look at several instances
Dim categoryName As String = "Network Interface"
'objX is the ID of the instances
Dim objX As Integer
'clear the combobox dropdown
ComboBox1.Items.Clear()
Try
If machineName.Length > 0 Then
pcc = New PerformanceCounterCategory(categoryName, machineName)
Else
pcc = New PerformanceCounterCategory(categoryName)
End If
instances = pcc.GetInstanceNames()
Catch ex As Exception
MsgBox("Unable to get instance information for " & "category ""{0}"" on " & IIf(machineName.Length > 0, "computer ""{1}"":", "this computer:"), categoryName, machineName)
MsgBox(ex.Message)
Return
End Try
If instances.Length = 0 Then
MsgBox("Category ""{0}"" on " & IIf(machineName.Length > 0, "computer ""{1}""", "this computer") & " is single-instance.", pcc.CategoryName, pcc.MachineName)
Else
' Otherwise, display the instances.
Array.Sort(instances)
For objX = 0 To instances.Length - 1
ComboBox1.Items.Add(instances(objX))
ComboBox1.Refresh()
ComboBox1.Update()
Next objX
End If
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|