From 22d17afa80ab8c64ce81f141ba8962f1013168b5 Mon Sep 17 00:00:00 2001 From: Francesco Montorsi Date: Thu, 19 Feb 2009 22:48:43 +0000 Subject: [PATCH] mention wxThreadEvent in wxEVT_CATEGORY_THREAD and in wxEvtHandler::QueueEvent git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59039 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- interface/wx/event.h | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/interface/wx/event.h b/interface/wx/event.h index de9ec40ad7..65b08c1678 100644 --- a/interface/wx/event.h +++ b/interface/wx/event.h @@ -54,6 +54,7 @@ enum wxEventCategory This category is for any event used to send notifications from the secondary threads to the main one or in general for notifications among different threads (which may or may not be user-generated). + See e.g. wxThreadEvent. */ wxEVT_CATEGORY_THREAD = 16, @@ -379,7 +380,7 @@ public: fields of this object are used by it, notably any wxString members of the event object must not be shallow copies of another wxString object as this would result in them still using the same string buffer behind - the scenes. For example + the scenes. For example: @code void FunctionInAWorkerThread(const wxString& str) { @@ -392,6 +393,20 @@ public: } @endcode + Note that you can use wxThreadEvent instead of wxCommandEvent + to avoid this problem: + @code + void FunctionInAWorkerThread(const wxString& str) + { + wxThreadEvent evt; + evt->SetString(str); + + // wxThreadEvent::Clone() makes sure that the internal wxString + // member is not shared by other wxString instances: + wxTheApp->QueueEvent( evt.Clone() ); + } + @endcode + Finally notice that this method automatically wakes up the event loop if it is currently idle by calling ::wxWakeUpIdle() so there is no need to do it manually when using it. -- 2.45.2