 |
| General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category.
** PLEASE BE SPECIFIC WITH YOUR QUESTION **
When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

January 7th, 2007, 09:08 PM
|
|
Authorized User
|
|
Join Date: Dec 2006
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
How to Run a Windows Service every 24 hours
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
__________________
Karthik
[Nothing is impossible]
|
|

January 8th, 2007, 12:51 AM
|
|
Authorized User
|
|
Join Date: Feb 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi,
Check the below code.. Modify accordingly to suit your needs.
The below code is self explantory
Code:
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
|
|

January 8th, 2007, 05:45 AM
|
|
Authorized User
|
|
Join Date: Dec 2006
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

January 9th, 2007, 01:22 AM
|
|
Authorized User
|
|
Join Date: Feb 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi,
Check this ...
Code:
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
|
|

January 9th, 2007, 09:13 PM
|
|
Authorized User
|
|
Join Date: Dec 2006
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

January 10th, 2007, 09:29 PM
|
|
Authorized User
|
|
Join Date: Dec 2006
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Karthik Simha,
Ur code is very helpfull for me.
Thanks a lot for ur help.
with affection,
Karthik
|
|
 |