I have a function that runs every minute:
var waitHandle = new AutoResetEvent(false);
ThreadPool.RegisterWaitForSingleObject(
waitHandle,
// Method to execute
(state, timeout) =>
{
Console.WriteLine(DateTime.Now + " START");
..some stuff
Console.WriteLine(DateTime.Now + " END");
},
null,
TimeSpan.FromMinutes(1),
false
);
This code executes well, but sample output is:
2016-08-16 18:45:55 START
2016-08-16 18:45:55 END
2016-08-16 18:46:55 START
2016-08-16 18:46:55 END
(or whatever second it happens to be at at the time of calling) I would like it to run like this:
2016-08-16 18:45:00 START
2016-08-16 18:45:00 END
2016-08-16 18:46:00 START
2016-08-16 18:46:00 END
So I want this function to run every minute, but when the seconds are at 0. How can I do that?