+ Reply to Thread
Results 1 to 2 of 2

Thread: How to wait for a given thread for infinite time?

  1. #1

    How to wait for a given thread for infinite time?

    How to wait for a given thread for infinite time?

  2. #2
    You can use WaitForSingleObject API and passing thread handle and INFINITE time to it.

    Example:

    Code:
    UINT ThreadFunc(LPVOID)
    {
    	//Do some task in this thread....
    	
    	AfxEndThread(0, TRUE) ;
    	return 0 ;
    }
    
    void CreateAThreadAndWaitForThread()
    {
    	CWinThread *pWinThread = AfxBeginThread(ThreadFunc, NULL) ;
    
    	DWORD dwResult = WaitForSingleObject(pWinThread->m_hThread, INFINITE) ;
    
    	switch (dwResult)
    	{
    	case WAIT_OBJECT_0:
    		printf("Thread has completed its task and ended!") ;
    		break ;
    	default:
    		break ;
    	}
    }

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts