|
Von Hause aus kann das der Timer leider nicht. Es hindert uns ja aber auch nichts daran, einen eigenen Timer zu schreiben und ihm eine Pause und Resume Funktion mitzugeben.
Das nachfolgende Klassenmodul stellt diese Funktionalität zur Verfügung:
''' <summary>
''' Advanced Timer mit Pause und Resume Funktion
''' </summary>
''' <remarks>Mai 2009 by VB-Power.net
''' http://www.vb-power.net/
''' </remarks>
Public Class AdvancedTimer
Private m_StopWatch As Stopwatch
Private m_Timer As Windows.Forms.Timer
Private m_Interval As Integer = 1000
Public Event Tick(ByVal sender As Object, ByVal e As EventArgs)
Public Event StatusChanged(ByVal sender As Object, ByVal e As AdvancedTimerEventArgs)
Public Sub New()
m_Timer = New Windows.Forms.Timer With {.Enabled = False, .Interval = 100}
AddHandler m_Timer.Tick, AddressOf iTick
m_StopWatch = New Stopwatch
End Sub
Public Property Interval() As Integer
Get
Return m_Interval
End Get
Set(ByVal value As Integer)
If value < 100 Then
Throw New Exception("Interval kann nicht kleiner 100 sein.")
Else
m_Interval = value
End If
End Set
End Property
Public Sub [Start]()
m_Timer.Start()
m_StopWatch.Reset()
m_StopWatch.Start()
RaiseEvent StatusChanged(Me, New AdvancedTimerEventArgs("Start"))
End Sub
Public Sub [Stop]()
m_Timer.Stop()
m_StopWatch.Reset()
RaiseEvent StatusChanged(Me, New AdvancedTimerEventArgs("Stop"))
End Sub
Public Sub [Pause]()
m_StopWatch.Stop()
RaiseEvent StatusChanged(Me, New AdvancedTimerEventArgs("Pause"))
End Sub
Public Sub [Resume]()
m_StopWatch.Start()
RaiseEvent StatusChanged(Me, New AdvancedTimerEventArgs("Resume"))
End Sub
Private Sub iTick(ByVal sender As Object, ByVal e As System.EventArgs)
If m_StopWatch.ElapsedMilliseconds >= m_Interval Then
RaiseEvent Tick(Me, New EventArgs)
m_StopWatch.Reset()
m_StopWatch.Start()
End If
End Sub
End Class
''' <summary>
''' EventArgs der Advanced Timer Klasse
''' </summary>
Public Class AdvancedTimerEventArgs
Inherits EventArgs
Private m_Status As String
Public Sub New(ByVal State As String)
m_Status = State
End Sub
Public ReadOnly Property Status() As String
Get
Return m_Status
End Get
End Property
End Class
Letzte Änderung: 17 May 2009 at 07:26
Zurück |