replace wxPostEvent with wxQueueEvent and update the thread sample description (the sample doesn't shows usage of wxMutexGuiEnter/Leave)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57449 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
c6427d4da4
commit
d1935bf638
@ -895,20 +895,19 @@ how tooltips can be centrally disabled and their latency controlled.
|
||||
@section page_samples_thread Thread Sample
|
||||
|
||||
This sample demonstrates use of threads in connection with GUI programs.
|
||||
|
||||
There are two fundamentally different ways to use threads in GUI programs and
|
||||
either way has to take care of the fact that the GUI library itself usually
|
||||
is not multi-threading safe, i.e. that it might crash if two threads try to
|
||||
access the GUI class simultaneously. One way to prevent that is have a normal
|
||||
GUI program in the main thread and some worker threads which work in the
|
||||
background. In order to make communication between the main thread and the
|
||||
worker threads possible, wxWidgets offers the wxPostEvent
|
||||
function and this sample makes use of this function.
|
||||
access the GUI class simultaneously.
|
||||
|
||||
The other way to use a so called Mutex (such as those offered in the wxMutex
|
||||
class) that prevent threads from accessing the GUI classes as long as any other
|
||||
thread accesses them. For this, wxWidgets has the wxMutexGuiEnter
|
||||
and wxMutexGuiLeave functions, both of which are
|
||||
used and tested in the sample as well.
|
||||
One way to prevent that is have a normal GUI program in the main thread and some
|
||||
worker threads which work in the background. In order to make communication between
|
||||
the main thread and the worker threads possible, wxWidgets offers the ::wxQueueEvent
|
||||
function and this sample demonstrates its usage.
|
||||
|
||||
The other way is to use a ::wxMutexGuiEnter and ::wxMutexGuiLeave functions, but
|
||||
this is not currently shown in the sample.
|
||||
|
||||
See also @ref overview_thread and wxThread.
|
||||
|
||||
|
@ -305,14 +305,14 @@ void *MyWorkerThread::Entry()
|
||||
event.SetInt( m_count );
|
||||
|
||||
// send in a thread-safe way
|
||||
wxPostEvent( m_frame, event );
|
||||
wxQueueEvent( m_frame, new wxCommandEvent(event) );
|
||||
|
||||
wxMilliSleep(200);
|
||||
}
|
||||
|
||||
wxCommandEvent event( wxEVT_COMMAND_MENU_SELECTED, WORKER_EVENT );
|
||||
event.SetInt(-1); // that's all
|
||||
wxPostEvent( m_frame, event );
|
||||
wxQueueEvent( m_frame, new wxCommandEvent(event) );
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@ -416,7 +416,7 @@ bool MyApp::OnInit()
|
||||
menuBar->Append(menuHelp, _T("&Help"));
|
||||
|
||||
frame->SetMenuBar(menuBar);
|
||||
|
||||
|
||||
// Show the frame
|
||||
frame->Show(true);
|
||||
|
||||
@ -431,7 +431,7 @@ MyFrame::MyFrame(wxFrame *frame, const wxString& title,
|
||||
: wxFrame(frame, wxID_ANY, title, wxPoint(x, y), wxSize(w, h))
|
||||
{
|
||||
SetIcon(wxIcon(sample_xpm));
|
||||
|
||||
|
||||
m_nRunning = m_nCount = 0;
|
||||
|
||||
m_dlgProgress = (wxProgressDialog *)NULL;
|
||||
|
Loading…
Reference in New Issue
Block a user