Restarting interrupted timers
Posted: Mon Apr 09, 2012 10:29 pm
When leaving an application state, the contained running timer is stopped. After returning to the state again, the timer continues counting at the place it was stopped. However, it is not possible (or at least I do not know how) to restart timer counting from the beginning when repeatedly switched to an application state. I could not achieve the desired behavior even with setting Timer.Interval = 0 on state's OnLeave and setting Timer.Interval = X on state's OnStart.
I tried to demonstrate the current behavior in the attached example. There are two application states A and B; A is the initial state. By pressing the key B, the application is switched to the state B running for approx. 10 seconds. After 10 seconds, the application is switched back to the state A automatically. Pressing the key A in state B returns application to the state A immediately. Now try the following:
1. Run application.
2. Press B to activate the state B.
3. Wait - after 10 seconds it is switched back to state A.
4. Press B again.
3. At any number less than 10 press A - application returns back to the state A.
4. Press B again.
5. Do not press anything and see counting - it never reaches 10, but only 10 - <previously interrupted counter>. This is the undesired behavior.
For now I use counting of App.Time instead of timers to overcome this problem. This workaround is shown in another attached example.
Is there some trick how to start counting of previously stopped timers from beginning? If not, would it be possible to add this feature? For instance, setting Timer.Interval or Timer.RepeatCount to some value should reset the timer counter.
I tried to demonstrate the current behavior in the attached example. There are two application states A and B; A is the initial state. By pressing the key B, the application is switched to the state B running for approx. 10 seconds. After 10 seconds, the application is switched back to the state A automatically. Pressing the key A in state B returns application to the state A immediately. Now try the following:
1. Run application.
2. Press B to activate the state B.
3. Wait - after 10 seconds it is switched back to state A.
4. Press B again.
3. At any number less than 10 press A - application returns back to the state A.
4. Press B again.
5. Do not press anything and see counting - it never reaches 10, but only 10 - <previously interrupted counter>. This is the undesired behavior.
For now I use counting of App.Time instead of timers to overcome this problem. This workaround is shown in another attached example.
Is there some trick how to start counting of previously stopped timers from beginning? If not, would it be possible to add this feature? For instance, setting Timer.Interval or Timer.RepeatCount to some value should reset the timer counter.