.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-01
许可协议 未经原作者许可禁止转载