Public Class TimeStamper
    Private filePath As String
    Private statusLabel As ToolStripItem

    Public Sub New(ByVal filePath As String)
        Me.filePath = filePath
    End Sub

    Public Sub New(ByVal filePath As String, ByVal statusLabel As ToolStripItem)
        Me.filePath = filePath
        Me.statusLabel = statusLabel
    End Sub

    Private LastUpdate As DateTime
    Public Sub WriteRegularTimeStamp()
        Do
            ' Write the file every 10 seconds.
            If DateTime.Now.Subtract(LastUpdate).TotalSeconds > 10 Then
                My.Computer.FileSystem.WriteAllText( _
                  filePath, DateTime.Now.ToLongTimeString + vbNewLine, True)
                LastUpdate = DateTime.Now

                ' Perform the update on the right thread.
                Dim method As New MethodInvoker(AddressOf UpdateStatusLabel)
                statusLabel.Owner.Invoke(method)
            End If
        Loop
    End Sub

    Private Sub UpdateStatusLabel()
        statusLabel.Text = "File updated at " + LastUpdate.ToLongTimeString()
    End Sub
End Class
