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

    how to know when a thread has ended

    What I would like to do is have process A launch process B, then be able to have process A know when process B is idle, after it has down some work(not after it has created the window).

    I've seen a function called WaitForSingleObjectEx, but am not sure if this is what I can use.

  2. #2
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    I am not sure whether I understood correctly since the subject differs from the actual description but if you need to wait until the newly created process is done with its initialization then you can use the function 'WaitForInputIdle()'...
    Code:
    STARTUPINFO         siStartupInfo;
    PROCESS_INFORMATION piProcessInfo;
    
    memset(&siStartupInfo, 0, sizeof(siStartupInfo));
    memset(&piProcessInfo, 0, sizeof(piProcessInfo));
    
    siStartupInfo.cb = sizeof(siStartupInfo);
    
    if(CreateProcess("c:\\windows\\notepad.exe", // Application name
                     " example.txt",             // Application arguments
                     0,
                     0,
                     FALSE,
                     CREATE_DEFAULT_ERROR_MODE,
                     0,
                     0,                          // Working directory
                     &siStartupInfo,
                     &piProcessInfo) == FALSE)
      // Could not start application -> call 'GetLastError()'
    
    // Wait for new process becoming idle
    if(::WaitForInputIdle(piProcessInfo.hProcess, INFINITE))
      // Error occured -> call '::GetLastError()'
    else
      // Process is idle

  3. #3
    Join Date
    Jan 2003
    Posts
    12
    I want process A to wait until after process B does what it was launched to do. Say for example process A launched process B so that Process B could encode a movie file; I want Process A to know when B is done processing that file, not just when it is done creating the window.

  4. #4
    Join Date
    Sep 2002
    Posts
    1,747
    So you mean you want to know when the second process has finished or will it still be running? To wait for the exit, just use CreateProcess to make it, and WaitForSingleObject on the process handle in the info structure. A sample can be found in the VC++ FAQs.
    */*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/

    "It's hard to believe in something you don't understand." -- the sidhi X-files episode

    galathaea: prankster, fablist, magician, liar

  5. #5
    Join Date
    Jan 2003
    Posts
    12

    Smile

    Thanks; I will try both suggestions since they give me a good place to start.

  6. #6
    Join Date
    Jan 2003
    Posts
    12
    what's the link to the faq?

  7. #7
    Join Date
    Sep 2002
    Posts
    1,747
    Here!
    */*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/

    "It's hard to believe in something you don't understand." -- the sidhi X-files episode

    galathaea: prankster, fablist, magician, liar

  8. #8
    Join Date
    Jan 2003
    Posts
    12
    thanks, I appreciate all the help!

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