From e03cdae72673067c896bdc8068d40618352a285e Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 7 Oct 2002 22:16:36 +0000 Subject: [PATCH] wxTimer::Start() only works from the main thread: mention it in the docs and add an assert in the code git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@17475 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/latex/wx/timer.tex | 2 ++ src/common/timercmn.cpp | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/docs/latex/wx/timer.tex b/docs/latex/wx/timer.tex index 7830183b5d..262e8332fc 100644 --- a/docs/latex/wx/timer.tex +++ b/docs/latex/wx/timer.tex @@ -20,6 +20,8 @@ In any case, you must start the timer with \helpref{Start}{wxtimerstart} after constructing it before it actually starts sending notifications. It can be stopped later with \helpref{Stop}{wxtimerstop}. +{\bf NB:} note that timer can only be used from the main thread currently. + \wxheading{Derived from} \helpref{wxObject}{wxobject} diff --git a/src/common/timercmn.cpp b/src/common/timercmn.cpp index 3bf88317e8..4853669d20 100644 --- a/src/common/timercmn.cpp +++ b/src/common/timercmn.cpp @@ -36,6 +36,7 @@ #ifndef WX_PRECOMP #include "wx/intl.h" #include "wx/log.h" + #include "wx/thread.h" #endif #include "wx/timer.h" @@ -131,6 +132,13 @@ void wxTimerBase::Notify() bool wxTimerBase::Start(int milliseconds, bool oneShot) { + // under MSW timers only work when they're started from the main thread so + // let the caller know about it +#ifdef wxUSE_THREADS + wxASSERT_MSG( wxThread::IsMain(), + _T("timer can only be started from the main thread") ); +#endif // wxUSE_THREADS + if ( IsRunning() ) { // not stopping the already running timer might work for some