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
This commit is contained in:
Francesco Montorsi
2009-02-19 22:48:43 +00:00
parent 335a0bc339
commit 22d17afa80

View File

@@ -54,6 +54,7 @@ enum wxEventCategory
This category is for any event used to send notifications from the This category is for any event used to send notifications from the
secondary threads to the main one or in general for notifications among secondary threads to the main one or in general for notifications among
different threads (which may or may not be user-generated). different threads (which may or may not be user-generated).
See e.g. wxThreadEvent.
*/ */
wxEVT_CATEGORY_THREAD = 16, wxEVT_CATEGORY_THREAD = 16,
@@ -379,7 +380,7 @@ public:
fields of this object are used by it, notably any wxString members of 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 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 as this would result in them still using the same string buffer behind
the scenes. For example the scenes. For example:
@code @code
void FunctionInAWorkerThread(const wxString& str) void FunctionInAWorkerThread(const wxString& str)
{ {
@@ -392,6 +393,20 @@ public:
} }
@endcode @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 Finally notice that this method automatically wakes up the event loop
if it is currently idle by calling ::wxWakeUpIdle() so there is no need if it is currently idle by calling ::wxWakeUpIdle() so there is no need
to do it manually when using it. to do it manually when using it.