code_junkie

Writing a more efficient clock function

Nov 12th, 2011
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. Public Class Form1
  2. Private WithEvents clockTimer As New Timer
  3. Private currentTime As DateTime = DateTime.MinValue
  4.  
  5. Private Sub ClockTick(ByVal sender As Object, _
  6. ByVal e As System.EventArgs) Handles clockTimer.Tick
  7.  
  8. UpdateTimer()
  9. DisplayTimer()
  10. End Sub
  11.  
  12. Private Sub UpdateTimer()
  13. currentTime = DateTime.Now
  14.  
  15. clockTimer.Stop()
  16. clockTimer.Interval = 1000 - currentTime.Millisecond
  17. clockTimer.Start()
  18. End Sub
  19.  
  20. Private Sub DisplayTimer()
  21. lblTime.Text = currentTime.ToString("T")
  22. End Sub
  23.  
  24. Private Sub Form1_Load(ByVal sender As System.Object, _
  25. ByVal e As System.EventArgs) Handles MyBase.Load
  26.  
  27. UpdateTimer()
  28. DisplayTimer()
  29. End Sub
  30. End Class
Add Comment
Please, Sign In to add comment