Performance Monitor : Chart « GUI Applications « VB.Net Tutorial

Home
VB.Net Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statements
5.Date Time
6.Class Module
7.Development
8.Collections
9.Generics
10.Attributes
11.Event
12.LINQ
13.Stream File
14.GUI
15.GUI Applications
16.Windows Presentation Foundation
17.2D Graphics
18.I18N Internationlization
19.Reflection
20.Regular Expressions
21.Security
22.Socket Network
23.Thread
24.Windows
25.XML
26.Database ADO.net
27.Design Patterns
VB.Net
VB.Net by API
VB.Net Tutorial » GUI Applications » Chart 
15.4.3.Performance Monitor
Imports System.Collections
Imports System.Diagnostics

Imports System.Windows.Forms

public class PerformanceMonitor
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is NothingThen
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents ObjectListBox As System.Windows.Forms.ListBox
    Friend WithEvents CounterListBox As System.Windows.Forms.ListBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents InstanceListBox As System.Windows.Forms.ListBox
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents CounterValueTextBox As System.Windows.Forms.TextBox
    Friend WithEvents CounterValueLabel As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()Private Sub InitializeComponent()
        Me.ObjectListBox = New System.Windows.Forms.ListBox()
        Me.CounterListBox = New System.Windows.Forms.ListBox()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.InstanceListBox = New System.Windows.Forms.ListBox()
        Me.Label3 = New System.Windows.Forms.Label()
        Me.CounterValueTextBox = New System.Windows.Forms.TextBox()
        Me.CounterValueLabel = New System.Windows.Forms.Label()
        Me.SuspendLayout()
        '
        'ObjectListBox
        '
        Me.ObjectListBox.Location = New System.Drawing.Point(1648)
        Me.ObjectListBox.Name = "ObjectListBox"
        Me.ObjectListBox.Size = New System.Drawing.Size(176134)
        Me.ObjectListBox.Sorted = True
        Me.ObjectListBox.TabIndex = 0
        '
        'CounterListBox
        '
        Me.CounterListBox.Location = New System.Drawing.Point(16208)
        Me.CounterListBox.Name = "CounterListBox"
        Me.CounterListBox.Size = New System.Drawing.Size(424134)
        Me.CounterListBox.TabIndex = 1
        '
        'Label1
        '
        Me.Label1.AutoSize = True
        Me.Label1.Location = New System.Drawing.Point(1632)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(11113)
        Me.Label1.TabIndex = 2
        Me.Label1.Text = "Performance Objects"
        '
        'Label2
        '
        Me.Label2.AutoSize = True
        Me.Label2.Location = New System.Drawing.Point(16192)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(11813)
        Me.Label2.TabIndex = 3
        Me.Label2.Text = "Performance Counters"
        '
        'InstanceListBox
        '
        Me.InstanceListBox.Location = New System.Drawing.Point(24048)
        Me.InstanceListBox.Name = "InstanceListBox"
        Me.InstanceListBox.Size = New System.Drawing.Size(200134)
        Me.InstanceListBox.TabIndex = 4
        '
        'Label3
        '
        Me.Label3.AutoSize = True
        Me.Label3.Location = New System.Drawing.Point(24032)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(8813)
        Me.Label3.TabIndex = 5
        Me.Label3.Text = "Instance Objects"
        '
        'CounterValueTextBox
        '
        Me.CounterValueTextBox.Location = New System.Drawing.Point(128360)
        Me.CounterValueTextBox.Name = "CounterValueTextBox"
        Me.CounterValueTextBox.Size = New System.Drawing.Size(31220)
        Me.CounterValueTextBox.TabIndex = 6
        Me.CounterValueTextBox.Text = ""
        Me.CounterValueTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'CounterValueLabel
        '
        Me.CounterValueLabel.AutoSize = True
        Me.CounterValueLabel.Location = New System.Drawing.Point(16360)
        Me.CounterValueLabel.Name = "CounterValueLabel"
        Me.CounterValueLabel.Size = New System.Drawing.Size(6213)
        Me.CounterValueLabel.TabIndex = 7
        Me.CounterValueLabel.Text = "Raw Value:"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(513)
        Me.ClientSize = New System.Drawing.Size(456469)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.CounterValueLabel, Me.CounterValueTextBox, Me.Label3, Me.InstanceListBox, Me.Label2, Me.Label1, Me.CounterListBox, Me.ObjectListBox})
        Me.Name = "Form1"
        Me.Text = "Performance1 - System.Diagnostiocs Performance Objects"
        Me.ResumeLayout(False)

    End Sub

#End Region
    Private counters As New ArrayList()
    Private counter As New PerformanceCounter()
    Private cat As New PerformanceCounterCategory()

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgsHandles MyBase.Load
        Dim categories As PerformanceCounterCategory()
        ObjectListBox.Sorted = True
        ObjectListBox.Items.Clear()
        categories = PerformanceCounterCategory.GetCategories
        Dim As Integer
        For i = To categories.Length - 1
            ObjectListBox.Items.Add(categories(i).CategoryName)
        Next
    End Sub

    Private Sub ObjectListBox_SelectedIndexChanged(ByVal sender _
    As System.Object, ByVal e As System.EventArgs_
    Handles ObjectListBox.SelectedIndexChanged
        InstanceListBox.Items.Clear()
        CounterListBox.Items.Clear()
        Dim As Integer
        Dim instances() As String
        cat = New PerformanceCounterCategory_
        ObjectListBox.SelectedItem.ToString())
        Try
            instances = cat.GetInstanceNames()
            If instances.Length = Then 'There are no instances for this object
                Dim counter As New PerformanceCounter()
                For Each counter In cat.GetCounters()
                    CounterListBox.Items.Add(counter.CounterName)
                Next
            Else
                'There ARE instances for this object so fill instanceListBox
                For i = To instances.Length - 1
                    InstanceListBox.Items.Add(instances(i).ToString())
                Next
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub InstanceListBox_SelectedIndexChanged_
    ByVal sender As System.Object, ByVal e As System.EventArgs_
    Handles InstanceListBox.SelectedIndexChanged
        CounterListBox.Items.Clear()
        cat = New PerformanceCounterCategory(ObjectListBox.SelectedItem.ToString())

        CounterListBox.Items.Clear()
        Dim As Integer
        counters.AddRange(cat.GetCounters(InstanceListBox.SelectedItem.ToString()))
        For Each counter In counters
            CounterListBox.Items.Add(counter.CounterName)
        Next

    End Sub


    Private Sub CounterListBox_SelectedIndexChanged(ByVal sender _
    As System.Object, ByVal e As System.EventArgs_
    Handles CounterListBox.SelectedIndexChanged
        Me.CounterValueTextBox.Text = CType(counters(CounterListBox.SelectedIndex), _
        PerformanceCounter).RawValue.ToString()
    End Sub
End Class
15.4.Chart
15.4.1.Custom ChartCustom Chart
15.4.2.Char CPU and MemoryChar CPU and Memory
15.4.3.Performance Monitor
15.4.4.GDI+ Line ChartGDI+ Line Chart
15.4.5.Thread GraphThread Graph
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.