Subject: How to Run a Windows Service every 24 hours
Posted By: srkarthik_82 Post Date: 1/7/2007 8:08:21 PM
Hiiii all,

  can anybody help me out for this????????I am new to windows service.
  I need to run my windows service at 12AM everyday.So where shud i write the intraval part.How to do that?

with regards,
Karthik
Reply By: karthiklsimha Reply Date: 1/7/2007 11:51:18 PM
Hi,

Check the below code.. Modify accordingly to suit your needs.
The below code is self explantory


    Dim objTmr As New System.Timers.Timer
    Protected Overrides Sub OnStart(ByVal args() As String)
        ' Add code here to start your service. This method should set things
        ' in motion so your service can do its work.
        objTmr.Interval = 1000 'One Second
        objTmr.Enabled = True 'Indicates whether the elapsed event is raised
        objTmr.AutoReset = True 'Indicates whether the event is fired each the interval elapses
        AddHandler objTmr.Elapsed, AddressOf objTmr_Elapsed
    End Sub

    Protected Overrides Sub OnStop()
        ' Add code here to perform any tear-down necessary to stop your service.
    End Sub

    Private Sub objTmr_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs)
        Dim objTime As New TimeSpan(12, 0, 0)
        If TimeSpan.Compare(DateTime.Now.TimeOfDay, objTime) >= 0 Then
            'Do your task here
        End If
    End Sub


Regards,
Karthik Simha
Reply By: srkarthik_82 Reply Date: 1/8/2007 4:45:58 AM
Hi karthik simha,

       thanks for ur post.but i am doin it in c#
 sorry i dint mention that in my post.
i am still struck on this issue.........

thanks a lot...
Karthik
Reply By: karthiklsimha Reply Date: 1/9/2007 12:22:31 AM
Hi,

Check this ...


System.Timers.Timer objTmr = new System.Timers.Timer(); 

protected override void OnStart(string[] args) 
{ 
 objTmr.Interval = 1000; 
 objTmr.Enabled = true; 
 objTmr.AutoReset = true; 
 objTmr.Elapsed += new System.Timers.ElapsedEventHandler(objTmr_Elapsed); 
} 

protected override void OnStop() 
{ 
} 

private void objTmr_Elapsed(object sender, System.Timers.ElapsedEventArgs e) 
{ 
 TimeSpan objTime = new TimeSpan(12, 0, 0); 
 if (TimeSpan.Compare(DateTime.Now.TimeOfDay, objTime) >= 0) { 
 } 
}


Regards,
Karthik Simha
Reply By: srkarthik_82 Reply Date: 1/9/2007 8:13:59 PM
Hi Simha,

     Thanks a lot for your help.I am working on it.I will get u posted once i finish it or if i have an issue.....


With affection,
Karthik
Reply By: srkarthik_82 Reply Date: 1/10/2007 8:29:41 PM
Hi Karthik Simha,

     Ur code is very helpfull for me.
Thanks a lot for ur help.

with affection,
Karthik

Go to topic 53816

Return to index page 67
Return to index page 66
Return to index page 65
Return to index page 64
Return to index page 63
Return to index page 62
Return to index page 61
Return to index page 60
Return to index page 59
Return to index page 58