CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Guest

    how do I know when a thread is completed?

    Hi,

    I'm using AfxBeginThread() to initiate a worker thread in my program. I want to initiate some action when this thread terminates. How can I detect whether the thread has been completed?

    Thanks,

    -Andrew


  2. #2
    Join Date
    May 1999
    Posts
    36

    Re: how do I know when a thread is completed?

    Hi,

    A couple of simple ways:

    1) Use a CEvent, and signal it in the thread just before it finishes...
    2) Send a message to the main thread from worker thread...

    There is probably a "right" way to do this, but I use both of those...

    HTH,

    Harvey Hawes

    Software Engineer
    BioScience Analysis Software Ltd.

    Masters Candidate
    Cardiovascular/Respiratory Sciences
    Faculty of Medicine
    University of Calgary
    Calgary, Alberta, Canada

  3. #3
    Join Date
    May 1999
    Location
    13 N 77 E
    Posts
    183

    Re: how do I know when a thread is completed?

    another way is to use WaitForSingleObject() which can take a thread handle


  4. #4
    Join Date
    Dec 1999
    Location
    Europe, Croatia
    Posts
    3

    Re: how do I know when a thread is completed?

    You have API called GetExitCodeThread(...).
    Look it up ...


  5. #5
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266

    Re: how do I know when a thread is completed?

    Search the knowledge base. The reason I am confident that that is a good idea is because I know that the two articles called "HOWTO: Detect All Program Terminations" and "Starting and Terminating Windows-Based Applications" are worth looking at.



    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

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