.Net CF下精确的计时器 用法: Dim t as New AtomicCF.Timer t.start() ....'Some functions here Dim TimeLapsed as Long = t.stop()
Imports System.Runtime.InteropServices Namespace AtomicCFNamespace AtomicCF PublicClass TimerClass Timer <DllImport("coredll.dll", EntryPoint:="QueryPerformanceCounter")> _ PublicSharedFunction QueryPerformanceCounter()Function QueryPerformanceCounter(ByRef perfCounter AsLong) AsInteger End Function <DllImport("coredll.dll", EntryPoint:="QueryPerformanceFrequency")> _ PublicSharedFunction QueryPerformanceFrequency()Function QueryPerformanceFrequency(ByRef frequency AsLong) AsInteger End Function Private m_frequency As Int64 Private m_start As Int64 PublicSub New()SubNew() If QueryPerformanceFrequency(m_frequency) =0Then ThrowNew ApplicationException EndIf 'Convert to ms. m_frequency =CLng(m_frequency /1000) End Sub PublicSub Start()Sub Start() If QueryPerformanceCounter(m_start) =0Then ThrowNew ApplicationException EndIf End Sub PublicFunction [()Function [Stop]() As Int64 Dim lStop As Int64 =0If QueryPerformanceCounter(lStop) =0ThenThrowNew ApplicationException EndIfReturnCLng((lStop - m_start) / m_frequency) End FunctionEnd ClassEnd Namespace Namespace