Question : trying to add a 24hour timer to my app

following a msdn article
http://msdn.microsoft.com/en-us/library/system.timers.timer.interval.aspx

with atimer = New System.Timers.Timer(86400000)   (24*60*1000)

and the AddHandler aTimer.Elapsed, AddressOf OnTimedEvent
gets ontimedevent is not decalred

I have trid putting the private shared atimer as system.timers.timer in my public class form1

Public Class Form1

    Dim csvfile As String = My.Application.Info.DirectoryPath & "\ians\test.csv"
    ' If File.Exists(String.Format("\ians\{0:g}log.csv",DateTime.now) Then
    'Dim outfile As New StreamWriter(String.Format("\ians\{0:g}log.csv", True))
    '   Else
    'Dim outfile As New StreamWriter(String.Format("\ians\{0:g}log.csv", False))
    '   End If
    Public outfile As StreamWriter
    Public Shared aTimer As System.Timers.Timer
    Dim Now As DateTime = DateTime.Now
    Private disptext1 As Object
    Private disptest2 As Object

whats the correct way in vb.net 2008 express

Answer : trying to add a 24hour timer to my app

use the "now" object to get the current time object and store it in a variable. Then you can use a timer control with large interval to check if the stored time is 24 hours ago by comparing it again with the "now" object.



Public Class Form1

    Dim startTime As Date
    Dim timerA As New Timer

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        startTime = Now
        timerA.Interval = (600000)
        AddHandler timerA.Tick, AddressOf passed10Min
        timerA.Start()
    End Sub

    Sub passed10Min()
        Dim d As Date = startTime
        d.AddDays(1)
        If Date.Compare(Now, d) <= 0 Then
            ''24 Passed

            timerA.Stop()

        Else
            ''24 haven't Passed
        End If
    End Sub


End Class


every 10 minutes this code will check if 24 hours have passed since the loading of the form.
Random Solutions  
 
programming4us programming4us