| 网站首页 | VB.Net实例分析 | .Net技术文摘 | 下载中心 | VB.Net书籍笔记 | .Net源码 | VBS脚本与组件调用 | Windows2008技术文摘 | 给我们留言 | 
最新公告:

  没有公告

您现在的位置: 乐博网 >> VB.Net实例分析 >> 实例学习笔记 >> 实例分析正文
最新推荐 更多内容
[图文]性能计数器编程(VB2010实例)
性能计数器编程(VB2010实例)
作者:Akyao    来源:乐博网收集     更新时间:2011-4-5

本文演示如何对性能计数器进行读写操作,以跟踪操作系统和 .NET Framework 应用程序的性能,来自乐博网,性能计数器编程(VB2010实例)

看看图,先了解一下性能计数器

 

共2个文件  MainForm.vb    CounterDisplayItem.vb

CounterDisplayItem.vb的VB2010源码如下:

' Copyright (c) Microsoft Corporation. All rights reserved.
''' <summary>
''' This class is used to store a counter, as well as define a
''' ToString() method that can be used by a ComboBox to display the
''' instance and name of the counter.
''' </summary>
''' <remarks></remarks>
Public Class CounterDisplayItem
    ' Store an instance of the counter inside the class.
    Private counterValue As PerformanceCounter

    ' Define a constructor, that requires that the PerformanceCounter
    ' be passed.  Store the passed counter.
    Public Sub New(ByVal inCounter As PerformanceCounter)
        ' Only store the passed value if it is, indeed, a counter.
        If TypeName(inCounter) = "PerformanceCounter" Then
            counterValue = inCounter
        Else
            counterValue = Nothing
        End If
    End Sub

    ' This property gets or sets the PerformanceCounter stored by
    ' a CounterDisplayItem object.
    Public Property Counter() As PerformanceCounter
        Get
            Return counterValue
        End Get
        Set(ByVal Value As PerformanceCounter)
            counterValue = Value
        End Set
    End Property

    ' This function overrides the ToString() method to display the
    ' information about the Counter that will be necessary for the
    ' user to select the proper counter.
    Public Overrides Function ToString() As String
        If counterValue IsNot Nothing Then
            Return counterValue.InstanceName + " - " + counterValue.CounterName
        Else
            Return ""
        End If
    End Function

    ' This property returns a True if the counter is a custom counter, and
    ' a false otherwise. Since there is no IsCustom property of a
    ' PerformanceCounter object, a special bit of code is used. This code
    ' attempts to set the ReadOnly property to False, then read a
    ' value from the counter. This will raise an exception if the counter
    ' is NOT a custom counter, otherwise it will not.
    Public ReadOnly Property IsCustom() As Boolean
        Get
            ' Store the current value of the ReadOnly property
            Dim isReadOnly As Boolean = counterValue.ReadOnly
            Try
                ' The only way NextValue works when ReadOnly
                ' is False, is if the Counter is a Custom counter.
                ' Unfortunately, there is no property in the
                ' PerformanceCounter object that already returns whether
                ' the counter is Custom.
                counterValue.ReadOnly = False
                counterValue.NextValue()
                ' If it makes it here, it is a custom counter.
                Return True
            Catch exc As Exception
                ' This is not a custom counter.
                Return False
            Finally
                ' Reset the value to the previous value.
                counterValue.ReadOnly = isReadOnly
            End Try
        End Get
    End Property
End Class

[1] [2] 下一页

  • 上一篇:

  • 下一篇:
  • 【字体: 】【打印此文】【关闭窗口
      相关文章:(只显示最新16条)
    管理计算机电源状态的类(VB2010实例)
    Tablet PC 上可用的文本识别选项(VB2010实例)
    Tablet PC 2005 中对笔势的系统识别(VB2010实例)
    自定义数据控件(VB2010实例)
    Tablet PC 2005 的区分上下文功能(VB2010实例)
    响应数字化仪触笔背面的橡皮擦(VB2010实例)
    WMI编程实例(VB2010实例)
    系统服务管理实例(VB2010实例)
    WMI获取系统性能信息的编程经验
    计数器类型使用详解(Win32_PerfRawData)
    采用WMI监视系统性能的实现方法
    进程管理(VB2010实例)
    显示进程组成模块(VB2010实例)
    任务管理器编程(VB2010实例)
    消息队列MSMQListener(VB2010实例)
    消息队列MSMQClient(VB2010实例)

    | 设为首页 | 加入收藏 | 联系站长 | | 友情链接 | 版权申明 |
    乐博网欢迎各种媒体转载我们的原创作品[转载请注明出处];我们鼓励更多VB.Net开发者一起加入研究与探讨;如发现文章访问错误、内容错误或版权疑问、内容有违相关法律(如涉及政治、色情、反动或散布虚假有害信息)等情况,请及时向我们举报,我们将及时纠正!
    联系邮箱:Shiny#vip.qq.com (#替换为@) QQ交流群: 40797788 [闽ICP备05014267号]