Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
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
 
Old January 7th, 2007, 09:08 PM
Authorized User
 
Join Date: Dec 2006
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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]
 
Old January 8th, 2007, 12:51 AM
Authorized User
 
Join Date: Feb 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to karthiklsimha
Default

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

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
 
Old January 9th, 2007, 01:22 AM
Authorized User
 
Join Date: Feb 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to karthiklsimha
Default

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

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

Hi Karthik Simha,

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

with affection,
Karthik





Similar Threads
Thread Thread Starter Forum Replies Last Post
Impersonate with windows service for Service A/C vinod_yadav1919 C# 0 October 18th, 2008 02:29 PM
Windows Service everest C# 1 March 8th, 2007 01:10 PM
Accessing Windows service from a windows app sajid08 C# 1 October 6th, 2006 10:25 AM
Display a random record for 24 hours palvin SQL Language 6 February 6th, 2006 10:36 AM
Windows Service bmains Pro VB.NET 2002/2003 2 January 21st, 2005 03:21 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.