Page 1 of 1

What happens when code in Notify() of wxTimer takes longer than the timer interval?

Posted: Mon Feb 22, 2016 12:52 pm
by macsinus
Is the next Notify() suppressed, queued or executed "simultaneously"?
Can/should I check for this case?
Would it be OK instead to use a single-shot timer with a StartOnce() at the end of the Notify()?
I have my doubts about the latter because the documentation states that "A timer can only be used from the main thread".
Thanks in advance!

Re: What happens when code in Notify() of wxTimer takes longer than the timer interval?

Posted: Mon Feb 22, 2016 2:12 pm
by eranif
Usually, I use a 'one-shot' timer and trigger another one in the handler itself.
This way I assure that the timer starts again once the handler code is done.
I have my doubts about the latter because the documentation states that "A timer can only be used from the main thread".
I don't see any problem with this, since the handler is also called in the main thread

Eran

Re: What happens when code in Notify() of wxTimer takes longer than the timer interval?

Posted: Mon Feb 22, 2016 3:12 pm
by T-Rex
On Windows the timer window message has the lowest priority and when you start the timer, the system does not guarantee that the message will be sent if the thread's event loop is busy processing other window messages. So if your timer window message handler works longer than the timer's interval, most likely you will not get the next timer message.
And since the main thread has only one event loop, then your window procedure will not get the next message until you process the current one, I assume.

Re: What happens when code in Notify() of wxTimer takes longer than the timer interval?

Posted: Mon Feb 22, 2016 3:15 pm
by macsinus
Hello Eran,
thank you for your quick reply and for the good news that the "chained" one-shot timer solution works - I'll go along this route.
Somehow I had assumed that the Notify() would be executed within a different thread.
Now that I know that it is in the main thread I don't need to have any headaches regarding display updating either. :D
Thanks also T-Rex; another good reason to do it this way.

Re: What happens when code in Notify() of wxTimer takes longer than the timer interval?

Posted: Wed Feb 24, 2016 8:02 am
by macsinus
Just to confirm - I've now implemented this so and it works like a charm.
Thanks again!