+
+wxThreadError wxThread::Delete(ExitCode *pRc)
+{
+ ExitCode rc = 0;
+
+ // Delete() is always safe to call, so consider all possible states
+
+ // has the thread started to run?
+ bool shouldResume = FALSE;
+
+ {
+ wxCriticalSectionLocker lock(m_critsect);
+
+ if ( m_internal->GetState() == STATE_NEW )
+ {
+ // WinThreadStart() will see it and terminate immediately
+ m_internal->SetState(STATE_EXITED);
+
+ shouldResume = TRUE;
+ }
+ }
+
+ // is the thread paused?
+ if ( shouldResume || IsPaused() )
+ Resume();
+
+ // does is still run?
+ if ( IsRunning() )
+ {
+ if ( IsMain() )
+ {
+ // set flag for wxIsWaitingForThread()
+ gs_waitingForThread = TRUE;
+
+#if wxUSE_GUI
+ wxBeginBusyCursor();
+#endif // wxUSE_GUI
+ }
+
+ // ask the thread to terminate
+ {
+ wxCriticalSectionLocker lock(m_critsect);
+
+ m_internal->Cancel();
+ }
+
+#if wxUSE_GUI
+ // simply wait for the thread to terminate
+ while( TestDestroy() )
+ {
+ ::YieldToAnyThread() ;
+ }
+#else // !wxUSE_GUI
+ // simply wait for the thread to terminate
+ while( TestDestroy() )
+ {
+ ::YieldToAnyThread() ;
+ }
+#endif // wxUSE_GUI/!wxUSE_GUI
+
+ if ( IsMain() )
+ {
+ gs_waitingForThread = FALSE;
+
+#if wxUSE_GUI
+ wxEndBusyCursor();
+#endif // wxUSE_GUI
+ }
+ }
+
+ // if ( !::GetExitCodeThread(hThread, (LPDWORD)&rc) )
+ {
+ wxLogLastError("GetExitCodeThread");
+
+ rc = (ExitCode)-1;
+ }
+
+ if ( IsDetached() )
+ {
+ // if the thread exits normally, this is done in WinThreadStart, but in
+ // this case it would have been too early because
+ // MsgWaitForMultipleObject() would fail if the therad handle was
+ // closed while we were waiting on it, so we must do it here
+ delete this;
+ }
+
+ // wxASSERT_MSG( (DWORD)rc != STILL_ACTIVE,
+ // wxT("thread must be already terminated.") );
+
+ if ( pRc )
+ *pRc = rc;
+
+ return rc == (ExitCode)-1 ? wxTHREAD_MISC_ERROR : wxTHREAD_NO_ERROR;
+}
+
+wxThreadError wxThread::Kill()
+{
+ if ( !IsRunning() )
+ return wxTHREAD_NOT_RUNNING;
+
+// if ( !::TerminateThread(m_internal->GetHandle(), (DWORD)-1) )
+ {
+ wxLogSysError(_("Couldn't terminate thread"));
+
+ return wxTHREAD_MISC_ERROR;
+ }
+
+ m_internal->Free();
+
+ if ( IsDetached() )
+ {
+ delete this;
+ }
+
+ return wxTHREAD_NO_ERROR;
+}
+
+void wxThread::Exit(ExitCode status)
+{
+ m_internal->Free();
+
+ if ( IsDetached() )
+ {
+ delete this;
+ }
+
+ m_internal->SetResult( status ) ;
+
+/*
+#if defined(__VISUALC__) || (defined(__BORLANDC__) && (__BORLANDC__ >= 0x500))
+ _endthreadex((unsigned)status);
+#else // !VC++
+ ::ExitThread((DWORD)status);
+#endif // VC++/!VC++