CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2004
    Posts
    62

    question with Thread Termination

    crucial: Is this a ok way to terminate a thread?.


    Code:
    CWinThread *pThread=NULL;
    
    UINT MyThread(LPVOID MyParam)
    {
      while(1)
      {
         If(IsTrue)
         {
          //Do Something
         }
      }
      AfxEndThread(0);
     	
    }
    
    pThread=AfxBeginThread(MyThread, NULL);
    
    
    close thread (Destroy Window):
    
    if(pThread->m_hThread != (void*)0xdddddddd)
    {
        DeleteObject(pThread);	
    }

  2. #2
    Join Date
    May 2003
    Location
    Pakistan
    Posts
    223

    Re: question with Thread Termination

    Quote Originally Posted by pharma
    crucial: Is this a ok way to terminate a thread?.


    Code:
    CWinThread *pThread=NULL;
    
    UINT MyThread(LPVOID MyParam)
    {
      while(1)
      {
         If(IsTrue)
         {
          //Do Something
         }
      }
      AfxEndThread(0);
     	
    }
    
    pThread=AfxBeginThread(MyThread, NULL);
    
    
    close thread (Destroy Window):
    
    if(pThread->m_hThread != (void*)0xdddddddd)
    {
        DeleteObject(pThread);	
    }

    In case of worker thread there is no need to use AfxEndThread as the Thread Proc will return it will autometically end the thread and delete its all memory.
    Unmanaged in a .NET world

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured