Several points:
- You do not have to create a new timer every hour.
- Setting the second parameter to infinite, makes you have to reload the timer manually. But... In this case, why should you?
- You make a difficult calculation to create a timespan from one hours form now: now + 1 hour - now. This can solved easily.
Try this:
class Program
{
private static Timer timer = new Timer(Write, null, TimeSpan.FromHours(1), TimeSpan.FromHours(1));
static void Main(string[] args)
{
}
static void Write(object data)
{
Console.WriteLine("foo");
}
}