Andreas Falkenhahn
2013-12-07 12:36:47 UTC
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.
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
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