Allow waiting for thread termination even without wxTheApp in wxMSW.

Attempts to wait for thread termination after wxTheApp was destroyed resulted
in an error in wxMSW since 2.9.something whereas it used to work in 2.8 and
also generally makes sense to be allowed. So do make this work again by
falling back to the simple non-interruptible wait for thread if we don't have
the application object any more.

Closes #13391.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_3_0_BRANCH@75914 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2014-02-17 23:55:17 +00:00
parent 302af8f3b3
commit e354c7a59a

View File

@@ -794,6 +794,8 @@ wxThreadInternal::WaitForTerminate(wxCriticalSection& cs,
gs_waitingForThread = true;
}
wxAppTraits& traits = wxApp::GetValidTraits();
// we can't just wait for the thread to terminate because it might be
// calling some GUI functions and so it will never terminate before we
// process the Windows messages that result from these functions
@@ -812,16 +814,9 @@ wxThreadInternal::WaitForTerminate(wxCriticalSection& cs,
}
}
wxAppTraits *traits = wxTheApp ? wxTheApp->GetTraits() : NULL;
if ( traits )
{
result = traits->WaitForThread(m_hThread, waitMode);
}
else // can't wait for the thread
{
// so kill it below
result = 0xFFFFFFFF;
}
// Wait for the thread while still processing events in the GUI apps or
// just simply wait for it in the console ones.
result = traits.WaitForThread(m_hThread, waitMode);
switch ( result )
{
@@ -846,7 +841,7 @@ wxThreadInternal::WaitForTerminate(wxCriticalSection& cs,
// the system might dead lock then
if ( wxThread::IsMain() )
{
if ( traits && !traits->DoMessageFromThreadWait() )
if ( !traits.DoMessageFromThreadWait() )
{
// WM_QUIT received: kill the thread
Kill();