Am I correct to assume that this logic (explained in the comment), is incorrect?
// While the current time is before the finish time, sleep the current thread.
// The timer will continue to run the getting of the rates
while (TimeSpan.Compare(DateTime.Now.TimeOfDay,this._finishTime.TimeOfDay) == -1)
It seems to me after looking at the MSDN Docs for TimeSpan.Compare that I should be looking for when the right parameter is 1, or 0 to achieve this functionality, but this code has been in there for years.
This is functionally equivalent to:
It seems like it will work correctly. Whenever it hits 0, the current time is equal to finishTime, and whenever it hits 1, the current time is greater than finishTime. In either case, the loop will end.
A better way would be:
This doesn’t care about
TimeOfDay, which creates an issue going from day to day (as @AakashM pointed out in the comments).