OVL_EXTERN bool AsyncEvent( gui_window *gui, gui_event gui_ev, void *param ) { gui_ctl_id id; switch( gui_ev ) { case GUI_INIT_DIALOG: dlg.cond = 0; GUISetFocus( gui, CTL_ASYNC_STOP ); AsyncWnd = gui; return( true ); case GUI_DIALOG_ESCAPE: AsyncWnd = 0; dlg.cond = StopAsync(); return( true ); case GUI_CONTROL_CLICKED : GUI_GETID( param, id ); switch( id ) { case CTL_ASYNC_STOP: AsyncWnd = 0; dlg.cond = StopAsync(); GUICloseDialog( gui ); return( true ); } return( false ); case GUI_DESTROY: AsyncWnd = 0; return( true ); } return( false ); }
APISocket::CSocket::~CSocket() { StopAsync(); Close(); m_sock = 0; }
BOOL CNktThread::Stop(__in DWORD dwTimeout) { HANDLE hEvents[2]; SIZE_T dwRetCode; DWORD dwExitCode; if (hThread != NULL) { if (dwThreadId == ::GetCurrentThreadId()) return StopAsync(); if ((dwInternalFlags & THREAD_INTERNAL_FLAG_BEINGRELEASED) == 0) { if (cThreadEndedOK.Wait(0) == FALSE) { cKillEvent.Set(); hEvents[0] = hThread; hEvents[1] = cThreadEndedOK.GetEventHandle(); for (;;) { //dwRetCode = WaitForMultipleObjects(2, hEvents, FALSE, (nTimeout > 100) ? 100 : dwTimeout); dwRetCode = ::WaitForSingleObject(hThread, (dwTimeout > 100) ? 100 : dwTimeout); //dwRetCode = CoWaitAndDispatchMessages((dwTimeout > 100) ? 100 : dwTimeout, 1, &hThread); if (dwRetCode == WAIT_TIMEOUT) { ::GetExitCodeThread(hThread, &dwExitCode); if (dwExitCode != STILL_ACTIVE) dwRetCode = WAIT_OBJECT_0; } if (dwRetCode != WAIT_TIMEOUT) break; if (dwTimeout != INFINITE) { if (dwTimeout > 100) dwTimeout -= 100; else break; } } } else { //if i'm here, it may be that C runtime is still freeing some stuff //so i wait 2 seconds to give him a chance to free all the stuff dwRetCode = ::WaitForSingleObject(hThread, 2000); } if (dwRetCode != WAIT_OBJECT_0 && dwRetCode != (WAIT_OBJECT_0+1)) ::TerminateThread(hThread, 0); } ::CloseHandle(hThread); hThread = NULL; } dwThreadId = 0; cThreadEndedOK.Destroy(); cKillEvent.Destroy(); dwInternalFlags &= ~THREAD_INTERNAL_FLAG_BEINGRELEASED; return TRUE; }
void CBackgroundInfoLoader::StopThread() { StopAsync(); if (m_thread) { m_thread->StopThread(); delete m_thread; m_thread = NULL; } m_vecItems.clear(); m_pVecItems = NULL; m_bIsLoading = false; }
/** * Stop the thread synchronously. * * Caller must lock the mutex. */ void Stop() { assert(mutex.IsLockedByCurrent()); StopAsync(); WaitStopped(); }