.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 LongAs Integer
        
End Function


        
<DllImport("coredll.dll", EntryPoint:="QueryPerformanceFrequency")> _
        
Public Shared Function QueryPerformanceFrequency(ByRef frequency As LongAs 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 ClassEnd Namespace
posted @ 2005-08-03 22:51  Dream world 梦想天空  阅读(605)  评论(2编辑  收藏  举报