Solved

Visual Studio 2008 Timer Control  - Timer1_Tick

Posted on 2008-11-02
2
8,449 Views
Last Modified: 2013-12-26
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
Comment
Question by:murbro
2 Comments
 
LVL 48

Accepted Solution

by:
jpaulino earned 500 total points
ID: 22865219
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
 

Author Closing Comment

by:murbro
ID: 31512610
thanks very much
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question