Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 Go to next message
koldo is currently offline  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 #49558 is a reply to message #49557] Thu, 01 March 2018 10:47 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 1091
Registered: August 2007
Senior Contributor
Hello Koldo,

Have you tried TimeCallback class? AFAIK it doesn't -directly- need a Ctrl (But it calls Upp::SetTimeCallback() too. Still, It may affect the behaviour -crash- differently ).

On console I haven't used it. But you can use a) a thread, or b) waitForSingleObject on Windows, and timer functions on posix. (Or you can emulate timer using sigtimedwait, creating a custom signal, or even using select call with a socket.)

Best regards,
Oblivion


[Updated on: Thu, 01 March 2018 11:13]

Report message to a moderator

Re: How to properly set a timer [message #49559 is a reply to message #49557] Thu, 01 March 2018 15:12 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
koldo wrote on Thu, 01 March 2018 10:19
Hello 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

Re: How to properly set a timer [message #49562 is a reply to message #49559] Fri, 02 March 2018 12:59 Go to previous message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
OK. Thank you.

Best regards
Iñaki
Previous Topic: [REQUEST]: Allow callback() template to work also with non-void and non-bool return types.
Next Topic: How to set a TimeCallback
Goto Forum:
  


Current Time: Thu Mar 28 16:55:41 CET 2024

Total time taken to generate the page: 0.01132 seconds