'------------------ 'Creator: aeonhack 'Site: elitevs.net 'Created: 11/30/2011 'Changed: 11/30/2011 'Version: 1.0.0 '------------------ Class PrecisionTimer Implements IDisposable Private _Enabled As Boolean ReadOnly Property Enabled() As Boolean Get Return _Enabled End Get End Property Private Handle As IntPtr Private TimerCallback As TimerDelegate _ Private Shared Function CreateTimerQueueTimer( _ ByRef handle As IntPtr, _ ByVal queue As IntPtr, _ ByVal callback As TimerDelegate, _ ByVal state As IntPtr, _ ByVal dueTime As UInteger, _ ByVal period As UInteger, _ ByVal flags As UInteger) As Boolean End Function _ Private Shared Function DeleteTimerQueueTimer( _ ByVal queue As IntPtr, _ ByVal handle As IntPtr, _ ByVal callback As IntPtr) As Boolean End Function Delegate Sub TimerDelegate(ByVal reserve As IntPtr, ByVal reserve As Boolean) Sub Create(ByVal dueTime As UInteger, ByVal period As UInteger, ByVal callback As TimerDelegate) If _Enabled Then Return TimerCallback = callback Dim Success As Boolean = CreateTimerQueueTimer(Handle, IntPtr.Zero, TimerCallback, IntPtr.Zero, dueTime, period, 0) If Not Success Then ThrowNewException("CreateTimerQueueTimer") _Enabled = Success End Sub Sub Delete() If Not _Enabled Then Return Dim Success As Boolean = DeleteTimerQueueTimer(IntPtr.Zero, Handle, IntPtr.Zero) If Not Success AndAlso Not Marshal.GetLastWin32Error = 997 Then ThrowNewException("DeleteTimerQueueTimer") End If _Enabled = Not Success End Sub Private Sub ThrowNewException(ByVal name As String) Throw New Exception(String.Format("{0} failed. Win32Error: {1}", name, Marshal.GetLastWin32Error)) End Sub Private Sub Dispose() Implements IDisposable.Dispose Delete() End Sub End Class