Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 8628
  • Last Modified:

Visual Studio 2008 Timer Control - Timer1_Tick

Hi

I have a timer control on a Windows form in Visual Studio 2008. I want the Timer1_Tick code
to run at the start of every minute. At the moment I have the Interval property set to 60000, but
the code runs based on when I enabled the Timer, eg 5 seconds after the start of every minute.
Is there a way to perhaps ensure that the timer gets enabled at the beginning of the new minute?
0
Murray Brown
Asked:
Murray Brown
1 Solution
 
jpaulinoCommented:
You can define at the beginning the exact interval to the right time and then you set 1 minute again-

Here's an example:

Public Class Form1
 
    Private WithEvents tm As Timer
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        tm = New Timer
        tm.Interval = New TimeSpan(Now.Hour, Now.Minute + 1, 0).Subtract(Now.TimeOfDay).TotalMilliseconds
        tm.Start()
    End Sub
 
    Private Sub tm_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tm.Tick
        Me.tm.Interval = 60000
        Me.Label1.Text = DateTime.Now.ToLongTimeString
    End Sub
 
End Class

Open in new window

0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
thanks very much
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now