How to wait a thread completion without blocking the gui?
Baldassarre Cesarano
baldassarre.cesarano at eunics.it
Fri Nov 16 04:14:24 PST 2007
Following the documentation, I wrote a class derived from wxThread =
passing a wxCondition and expect the completion with condition.Wait () =
=
I tried all combinations wxTHREAD_JOINABLE/wxTHREAD_DETACHED =
and entering in the body of thread =
wxYield and/or wxThread:Sleep!!!!!
=
However, the user interface remains blocked
=
How can I fix this?
Baldo
=
PS. This is the sample code
-----------------------------------------------
class Test_SignallingThread : public wxThread {
public:
Test_SignallingThread( wxMutex *mutex,
wxCondition *condition,
long msTimeout
)
// : wxThread( wxTHREAD_JOINABLE )
// : wxThread( wxTHREAD_DETACHED )
{
m_mutex =3D mutex;
m_condition =3D condition;
m_msTimeout =3D msTimeout;
Create();
}
virtual ExitCode Entry();
private:
wxMutex* m_mutex;
wxCondition* m_condition;
long m_msTimeout;
};
=
wxThread::ExitCode Test_SignallingThread::Entry() {
wxStopWatch msElapsed;
msElapsed.Start(0);
while( ( msElapsed.Time() <=3D m_msTimeout ) //TimeOut
){
// Do some jobs
//.........
// wxYield();
// wxThread::Sleep(80);
}
msElapsed.Pause();
=
wxMutexLocker lock( *m_mutex );
m_condition->Broadcast();
return NULL;
}
=
.....................
.....(from a men=F9 event)
void MyFrame::OnTest(wxCommandEvent& WXUNUSED(event)) {
wxMutex mutex;
wxCondition condition( mutex );
mutex.Lock();
=
Test_SignallingThread* thread =3D new Test_SignallingThread( &mutex,
&condition, 10000 );
if ( thread->Run() !=3D wxTHREAD_NO_ERROR ) {
wxLogError(wxT("Can't start thread!"));
}
condition.Wait();
}
=
=
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.wxwidgets.org/pipermail/wx-dev/attachments/20071116/86280=
20b/attachment.htm
More information about the wx-dev
mailing list