用户操作
[留言]  [发消息]  [加为好友] 
订阅我的博客
XML聚合    FeedSky
订阅到鲜果
订阅到Google
订阅到抓虾
hesicong的公告
<font size="3" color="#FF0000">介于CSDN博客做得越来越垃圾,此博客停止更新并且不再进行维护,请访问www.hesicong.net或者www.april1985.com获取最新文章,谢谢!</font>
文章分类
存档

原创  .Net CF下精确的计时器 收藏

.Net CF下精确的计时器
用法:
Dim t as New AtomicCF.Timer
t.start()
....'Some functions here
Dim TimeLapsed as Long = t.stop()

代码:

Imports System.Runtime.InteropServices
Namespace AtomicCF

    Public Class Timer
        <DllImport("coredll.dll", EntryPoint:="QueryPerformanceCounter")> _
        Public Shared Function QueryPerformanceCounter(ByRef perfCounter As Long) As Integer
        End Function

        <DllImport("coredll.dll", EntryPoint:="QueryPerformanceFrequency")> _
        Public Shared Function QueryPerformanceFrequency(ByRef frequency As Long) As Integer
        End Function

        Private m_frequency As Int64
        Private m_start As Int64

        Public Sub New()
            If QueryPerformanceFrequency(m_frequency) = 0 Then
                Throw New ApplicationException
            End If
            'Convert to ms.
            m_frequency = CLng(m_frequency / 1000)
        End Sub

        Public Sub Start()
            If QueryPerformanceCounter(m_start) = 0 Then
                Throw New ApplicationException
            End If
        End Sub

        Public Function [Stop]() As Int64
            Dim lStop As Int64 = 0
            If QueryPerformanceCounter(lStop) = 0 Then
                Throw New ApplicationException
            End If
            Return CLng((lStop - m_start) / m_frequency)
        End Function
    End Class
End Namespace

发表于 @ 2005年08月02日 15:32:00 | 评论( loading... ) | 编辑| 举报| 收藏

旧一篇:Control your PDA's LED | 新一篇:公告:此博客开始更新

  • 发表评论
  • 评论内容:
  •  
Copyright © hesicong
Powered by CSDN Blog