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

    Invalid thread handle

    Hello, I am creating a thread (let's call it thread B) from within another thread (thread A) , and saving the thread handle returned by AfxBeginThread. Before returning from thread A, I wait for thread B to terminate, using WaitForSingleObject with the thread handle. Problem is: if thread B already terminated (it terminates when the thread function returns, not by endthread) by the time I call WaitForSingleObject, this routine fails, returning WAIT_FAILED, and when I call GetLastError I get error no. 6: "The handle is invalid." Since I have handles leak, I suspect that the handle is not really closed (there is no point to call CloseHandle on it, if it's invalid). Any idea why the handle becomes invalid? maybe the fact that I create the thread from withing another thread is problematic? thanks
    It is nice to be important, but more important to be nice.

  2. #2
    Join Date
    Jun 2004
    Location
    India
    Posts
    432

    Re: Invalid thread handle

    CWinThread invalidates the handle when the thread ceases to exist. That would explain it.
    Say no to supplying ready made code for homework/work assignments!!

    Please rate this post!

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