windows threading timer in windows service vb.net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sarabonn
    New Member
    • Nov 2008
    • 69

    windows threading timer in windows service vb.net

    Hallo everyone,

    I am using vs 2005 with vb.net. I want to run a windows service once a day automatically. I used the threading timer and it runs perfect for the first and does not run automatically everyday. i kept the timedelay 360000 * 24 so that after the service first time start it will calculate 1 day time.. here is the code

    Private Timer1 As System.Threadin g.Timer
    Private Const Timedelay As Long = 3600000 * 24


    Protected Overrides Sub OnStart(ByVal args() As String)
    Dim Timerdelegate As TimerCallback = AddressOf Timer1_Tick
    Dim AutoEvent As New AutoResetEvent( False)
    Timer1 = New Timer(Timerdele gate, AutoEvent, 0, Timedelay)
    'EventLog.Write Entry("Simple Service")
    End Sub


    In the timer tick the change the timedelay

    Private Sub Timer1_Tick(ByV al stateinfo As Object)
    // here is the code that run when the service start

    Call Timer1.Change(T imedelay, Timedelay)
    End Sub

    is this correct or any changes ?..

    thank you..

    Dinesh.
  • PRR
    Recognized Expert Contributor
    • Dec 2007
    • 750

    #2
    Do you want to run windows service once a day or you want a certain task to run once a day?
    If you want the windows service to run once a day, another service will have to start your service. If you intent to run a task once a day, have a Boolean variable that checks task run and two datetime variables( to compare the date for new day)

    Comment

    Working...