Egg Timer
The egg timer application is a simple countdown timer program that allows users to set a time in hours mins and secs, after which a dialog will be displayed displaying a user specified message.
Additional requirements
- The timer can also be stopped, paused or reset at any time during the countdown.
- Window buttons will only be available when appropriate
- During Countdown the time will be updated in both the Titlebar and the time windows.
- When reset the time windows will return to the last user set time, ready for another run.
CDL Solution
In this solution the Ctrl store is set by the GUI when the user presses Start and contains the duration of the countdown. This triggers the blocked thread to wake and start the countdown.
The Timer thread will execute in a loop re-waking every second. When it wakes it updates the Time store with a reduced countdown. When the duration reaches 0 the Thread sets the Alarm store. At each state change (Active, Stopped, Paused) the Thread will update the State store. Before the Thread sleeps each second, it checks the Ctrl store for any GUI requested changes (Pause, Stop, Restart).
When the countdown reaches 0 the Thread the returns to the blocked state waiting for a new countdown from the GUI.
The three callback functions respond to each of the stores and effect the changes on the Display.
Alarm - pops up the Alarm Dialog
Time - updates the times in the windows and title bar
State - updates the states of each of the buttons depending on the current system state
The Egg Timer solution is available as a MSVisual Studio 2005 solution package from the Connective Logic Web site.
|
Documentation Under Construction This documentation is updated weekly. Please try again later. We apologize for any inconvenience. |
Further Enhancements
The example solution does not have an audible signal. This would not be difficult to add to the code, but since it is purely a MFC feature and hence MFC code, it will be left as an exercise for the reader.
In this simple application the responsiveness to GUI resets (upto 1 sec) is not really an issue. However, in a more sophisticated program we could improve this responsiveness by
a. running the Timer Thread in a finer loop (eg 0.1 sec) but this could waste a lot of system resources/performance.
b. use a separate 'Tick', so that the Timer can block on both the Ctrl store and the 'Tick'. In this case the old Timer Thread could also be replaced with a Method saving on the system resources/performance.