Discussion:
wxTimer questions
Andreas Falkenhahn
2013-12-07 12:36:47 UTC
Permalink
Hi,

I've derived a new timer class from wxTimer and have two questions about it:

1) Will the Notify() method only be called while the wxWidgets main loop
is running or will it also be called if the main loop isn't there? I've
had a quick look at the source and it seems that on Win32 the timer is
delegated to the Win32 API SetTimer(), i.e. it should run independently
from the wxWidgets main loop while the generic implementation seems to
be dependent on the main loop because wxTimerScheduler::NotifyTimers()
is called from the main loop.

2) Is it safe to delete the wxTimer from within the Notify() callback?
The generic implementation has this comment in Notify():

// NB: this is a hack: wxTimerScheduler must have some way of knowing
// that wxTimer object was deleted under its hands -- this may
// happen if somebody is really nasty and deletes the timer
// from wxTimer::Notify()

Deleting the wxTimer inside Notify() is considered "really nasty" but
I think it is a common thing to do. For example, if you have a one
shot timer you'll normally want to delete it inside your Notify()
callback, won't you?

Thanks for some clarification on this. Once again, this question applies
to wxWidgets 2.8.12.
--
Best regards,
Andreas Falkenhahn mailto:***@falkenhahn.com
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
Vadim Zeitlin
2013-12-18 14:46:55 UTC
Permalink
On Sat, 7 Dec 2013 13:36:47 +0100 Andreas Falkenhahn wrote:

AF> Hi,
AF>
AF> I've derived a new timer class from wxTimer and have two questions about it:
AF>
AF> 1) Will the Notify() method only be called while the wxWidgets main loop
AF> is running

Yes.

AF> or will it also be called if the main loop isn't there? I've
AF> had a quick look at the source and it seems that on Win32 the timer is
AF> delegated to the Win32 API SetTimer(), i.e. it should run independently
AF> from the wxWidgets main loop

wxTimerEvent will only be generated if someone dispatches the events. It's
true that, in principle, it could be something else using Win32 API
directly and not our own event loop. But no timer events will be generated
if the Windows messages are not dispatched at all.

AF> 2) Is it safe to delete the wxTimer from within the Notify() callback?

It should be.

Regards,
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/
asif saeed
2013-12-18 15:31:05 UTC
Permalink
Hi Vadim,
Post by Vadim Zeitlin
AF>
AF> 1) Will the Notify() method only be called while the wxWidgets main loop
AF> is running
Yes.
AF> or will it also be called if the main loop isn't there? I've
AF> had a quick look at the source and it seems that on Win32 the timer is
AF> delegated to the Win32 API SetTimer(), i.e. it should run independently
AF> from the wxWidgets main loop
wxTimerEvent will only be generated if someone dispatches the events. It's
true that, in principle, it could be something else using Win32 API
directly and not our own event loop. But no timer events will be generated
if the Windows messages are not dispatched at all.
AF> 2) Is it safe to delete the wxTimer from within the Notify() callback?
It should be.
Will I still get wxTimer events at correct time intervals even if my
application makes time adjustments in system time from a central server?

Best regards,
-Asif
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
Vadim Zeitlin
2013-12-18 15:58:30 UTC
Permalink
On Wed, 18 Dec 2013 20:31:05 +0500 asif saeed wrote:

as> Will I still get wxTimer events at correct time intervals even if my
as> application makes time adjustments in system time from a central server?

I think you should but you really need to test it yourself.

Regards,
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/
asif saeed
2013-12-18 16:41:20 UTC
Permalink
Hi Vadim,
Post by Vadim Zeitlin
as> Will I still get wxTimer events at correct time intervals even if my
as> application makes time adjustments in system time from a central server?
I think you should but you really need to test it yourself.
Thanks very much for replying. I asked the question because you talked
about the underlying Win32 timer implementation in your earlier post in
this thread. I have an application that uses Win32 timer and yet changes
the system time to adjust with the central time server time. So, I think if
the underlying implementation of wxTimer is one of Win32 native timer then
nothing should go wrong if the application does change system time while
using the wxTimer.

Best regards,
-Asif
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
Loading...