I need to start a C# service running on a server once per day at 3AM. I think that I can do it with a thread.sleep()
or by comparing DateTime.Now
with 3AM in code that runs 24/7.
Do you have a better solution?
I need to start a C# service running on a server once per day at 3AM. I think that I can do it with a thread.sleep()
or by comparing DateTime.Now
with 3AM in code that runs 24/7.
Do you have a better solution?
Write a console app or equivalent, and use the Windows Task Scheduler to run it daily.
I've used Scheduled Tasks successfully for backups, but I have a word of caution ...
Scheduled tasks may not be performed if you log out. I'm not sure if this can be overridden, but I have been caught out by tasks not performed because Windows automatically updates, reboots and sits waiting for me to log-in.
Another consideration is that 3AM is a time when many users would normally be logged out.
If you are expecting a file every night, instead of worrying about when it arrives, just get an event fired when it does.
Look at:
System.IO.FileSystemWatcher
Why not set this up to run as a scheduled task? Have it execute and then exit. Set up Windows to start the process as a scheduled task at 3:00 AM daily.