Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / May 2007

Tip: Looking for answers? Try searching our database.

Scheduled task windows service

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jeff - 12 May 2007 21:36 GMT
Hello...
I need to add a timer to a windows sevice to start a program every day at
the same time.  Because timers aren't set up to do this (run at a specific
time), I know I need to check the time and establish an interval so the timer
knows when to start my program.  Then I guess I need to check the time and
re-establish the interval again.  I'm sure this is a common thing to do, and
I am trying to find some examples to look at. I'm just looking for a quick
and dirty example.
Thanks for any help...
Brian Schwartz - 14 May 2007 17:29 GMT
You're on the right track.

In your service initialization code:
- Create a System.Timers.Timer object
- Set the Interval (perhaps to 1000, to check the current time once every
second, or 10,000 to check every minute)
- Attach to the timer's Elapsed event
- Enable the timer

When the Elapsed event fires:
- check the system time
- if the system time is the time of day you are waiting for, run the other
app; otherwise do nothing

You will probably want to keep a flag that indicates the last day the
program was run, and when you are checking the current system time, see if
it is not only on, but also possibly past, the time you want to run your
other program, and also check the last-run flag to make sure it is not
today. This way you won't miss a day if the system gets busy and the timer
doesn't have the opportunity to fire on the exact second or minute you're
watching for.

Signature

Brian Schwartz
FishNet Components
http://www.fishnetcomponents.com
Fish Grid .NET Light: Powerful Layouts for Small Datasets

> Hello...
> I need to add a timer to a windows sevice to start a program every day at
[quoted text clipped - 7 lines]
> and dirty example.
> Thanks for any help...

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.