.Net CF下精确的计时器

不问归期 提交于 2019-11-26 15:09:45

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

None.gifImports System.Runtime.InteropServices
ExpandedBlockStart.gifContractedBlock.gif
Namespace AtomicCFNamespace AtomicCF
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public Class TimerClass Timer
InBlock.gif        
<DllImport("coredll.dll", EntryPoint:="QueryPerformanceCounter")> _
ExpandedSubBlockStart.gifContractedSubBlock.gif        
Public Shared Function QueryPerformanceCounter()Function QueryPerformanceCounter(ByRef perfCounter As LongAs Integer
ExpandedSubBlockEnd.gif        
End Function

InBlock.gif
InBlock.gif        
<DllImport("coredll.dll", EntryPoint:="QueryPerformanceFrequency")> _
ExpandedSubBlockStart.gifContractedSubBlock.gif        
Public Shared Function QueryPerformanceFrequency()Function QueryPerformanceFrequency(ByRef frequency As LongAs Integer
ExpandedSubBlockEnd.gif        
End Function

InBlock.gif
InBlock.gif        
Private m_frequency As Int64
InBlock.gif        
Private m_start As Int64
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
Public Sub New()Sub New()
InBlock.gif            
If QueryPerformanceFrequency(m_frequency) = 0 Then
InBlock.gif                
Throw New ApplicationException
InBlock.gif            
End If
InBlock.gif            
'Convert to ms.
InBlock.gif
            m_frequency = CLng(m_frequency / 1000)
ExpandedSubBlockEnd.gif        
End Sub

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
Public Sub Start()Sub Start()
InBlock.gif            
If QueryPerformanceCounter(m_start) = 0 Then
InBlock.gif                
Throw New ApplicationException
InBlock.gif            
End If
ExpandedSubBlockEnd.gif        
End Sub

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
Public Function [()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 Namespace
InBlock.gif

转载于:https://www.cnblogs.com/hesicong/archive/2005/08/03/206997.html

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!