Der Titel sagt eigentlich alles.
Dieser Timer tickt halbwegs synchron zur Systemuhr, und zwar zur jeden vollen Sekunde.
Anwendungsbeispiel:
Dieser Timer tickt halbwegs synchron zur Systemuhr, und zwar zur jeden vollen Sekunde.
VB.NET-Quellcode
- Imports System.ComponentModel
- ''' <summary>
- ''' Synchronized to the system clock, ticks every full second.
- ''' </summary>
- <ToolboxItem(True)>
- <ToolboxBitmap(GetType(Timer), "System.Windows.Forms.Timer.bmp")>
- Public Class SystemClockTimer
- Inherits Timer
- ''' <summary>
- ''' Will be calculated automatically.
- ''' </summary>
- ''' <returns>
- ''' Calculated milliseconds as Integer.
- ''' </returns>
- <Browsable(False)>
- <DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)>
- <EditorBrowsable(EditorBrowsableState.Never)>
- Public Shadows ReadOnly Property Interval() As Integer
- Get
- Return Math.Max(1, 1000 - Date.Now.Millisecond)
- End Get
- End Property
- Public Overloads Property Enabled() As Boolean
- Get
- Return MyBase.Enabled
- End Get
- Set(value As Boolean)
- MyBase.Enabled = value
- If value Then
- MyBase.Interval = Interval
- MyBase.Start()
- Else
- MyBase.Stop()
- End If
- End Set
- End Property
- Public Shadows Event Tick(sender As Object, e As SystemClockTimerEventArgs)
- Private Sub MyBase_Tick(sender As Object, e As EventArgs) Handles MyBase.Tick
- RaiseEvent Tick(sender, New SystemClockTimerEventArgs())
- MyBase.Interval = Interval
- End Sub
- Public Overloads Sub Start()
- Enabled = True
- End Sub
- Public Overloads Sub [Stop]()
- Enabled = False
- End Sub
- End Class
- Public Class SystemClockTimerEventArgs
- Inherits EventArgs
- Public ReadOnly Property Now As Date
- Sub New()
- Now = Date.Now
- End Sub
- End Class
Anwendungsbeispiel:
bit.ly/DotNetSearch
Code Konverter:
Online: @ developerfusion.com, @ telerik.com
Offline stand alone: Convert .NET, C# to VB Converter
VS Extensions: Convert .NET (Based on .NET 4.5), Language Convert
Code Konverter:
Online: @ developerfusion.com, @ telerik.com
Offline stand alone: Convert .NET, C# to VB Converter
VS Extensions: Convert .NET (Based on .NET 4.5), Language Convert