Home » U++ Library support » U++ Callbacks and Timers » How to properly set a timer
How to properly set a timer [message #49557] |
Thu, 01 March 2018 10:19 |
|
koldo
Messages: 3355 Registered: August 2008
|
Senior Veteran |
|
|
Hello all
This question is strangely derived from this post.
I wanted to ask you how to set properly a timer. Three options:
1. Inside a class derived from Ctrl
SetTimeCallback(time, THISBACK(callbackFunction));
2. In a GUI program, in a class not derived from Ctrl
¿?¿?¿?
3. In a console program
¿?¿?¿?
For the option 2, I have used historically ::SetTimeCallback(time, THISBACK(callbackFunction));
However, for unknown reasons, it may sometimes crash the program.
Best regards
Iñaki
|
|
|
|
Re: How to properly set a timer [message #49559 is a reply to message #49557] |
Thu, 01 March 2018 15:12 |
|
mirek
Messages: 13975 Registered: November 2005
|
Ultimate Member |
|
|
koldo wrote on Thu, 01 March 2018 10:19Hello all
This question is strangely derived from this post.
I wanted to ask you how to set properly a timer. Three options:
Generally, you have to avoid situation where callback is invoked after target instance is destroyed.
Quote:
1. Inside a class derived from Ctrl
SetTimeCallback(time, THISBACK(callbackFunction));
In client code, use TimerCallback. TimerCallback destructor removes the callback from the timer queue if necessarry.
You can use SetTimeCallback directly, but then you have to rember id and remove in destructor.
Quote:
2. In a GUI program, in a class not derived from Ctrl
Use SetTimeCallback directly, but remember to remove callback from the queue as necessary.
Quote:
3. In a console program
You cannot. It is CtrlCore feature...
Mirek
[Updated on: Thu, 01 March 2018 15:12] Report message to a moderator
|
|
|
|
Goto Forum:
Current Time: Fri Mar 29 12:24:31 CET 2024
Total time taken to generate the page: 0.01180 seconds
|