11-28-2011 02:22 PM
Here is something that I use a lot. You can set the wait to next year and still have the ability to stop at any time.
Open and run test timer. Note that there is no Wait (mS) function in the loop. You will want to add one so it isn't greedy.
11-28-2011 02:57 PM
@Steve Chandler wrote:
@Mark Yedinak wrote:
The only comment I have is that if the user is only looking for an event every Friday set your timeout accordingly. A timeout every 50 ms is WAY TOO many timeouts when looking for an event that occurs once a week.
Yes indeed, unless you want to know it's Friday right away which I usually do
Better to come up with some algorithm that adjusts the timeout as Friday aproaches until it is eventually set to 0. But even firing an event every 50mS all week long will not hurt anything. Overkill yes but the CPU load will not be noticable and memory leaks will not happen. It should be fine (I think)
If you are using a reasonabley fast timeout for polling purposes I see no need to adjust the timeout period as you get close to Friday. I doubt the timing has to be that precise if you are dealing with a weekely event. I am sure your tolerance is probably several hundred milliseconds if not several seconds.
But yes, a self adjusting algorith is a very elegant solution and it is one that I do use.
I also agree that using the 50 ms timeout probably won't hurt but part of the design process is to minimize unnecessary processing. If your tolerance is several seconds then a timeout of 1 second will reduce the number of events to 1/20. It is always a prudent design decision to use practical and reasonable values for such events.
11-28-2011 03:07 PM - edited 11-28-2011 03:08 PM
@Mark Yedinak wrote:
@Steve Chandler wrote:
@Mark Yedinak wrote:
The only comment I have is that if the user is only looking for an event every Friday set your timeout accordingly. A timeout every 50 ms is WAY TOO many timeouts when looking for an event that occurs once a week.
Yes indeed, unless you want to know it's Friday right away which I usually do
Better to come up with some algorithm that adjusts the timeout as Friday aproaches until it is eventually set to 0. But even firing an event every 50mS all week long will not hurt anything. Overkill yes but the CPU load will not be noticable and memory leaks will not happen. It should be fine (I think)
If you are using a reasonabley fast timeout for polling purposes I see no need to adjust the timeout period as you get close to Friday. I doubt the timing has to be that precise if you are dealing with a weekely event. I am sure your tolerance is probably several hundred milliseconds if not several seconds.
But yes, a self adjusting algorith is a very elegant solution and it is one that I do use.
I also agree that using the 50 ms timeout probably won't hurt but part of the design process is to minimize unnecessary processing. If your tolerance is several seconds then a timeout of 1 second will reduce the number of events to 1/20. It is always a prudent design decision to use practical and reasonable values for such events.
And, There is an elegnt example of a long-term suitable wait over here. I would suggest modifying it slightly to listen for a "stop early" command. Or your weekend might never come.
11-28-2011 09:31 PM
Thanks guys for your replies. I will check it out right now and come back with a good solution as your comments.