How to execute code in a C# service one time per day at the same hour

c#, scheduling, service

Solution

Write a console app or equivalent, and use the Windows Task Scheduler to run it daily.

Problem

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?

Original source