Click to See Complete Forum and Search --> : how to know when a thread has ended
thpsthc
January 9th, 2003, 04:25 PM
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.
Andreas Masur
January 9th, 2003, 04:44 PM
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()'...
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
thpsthc
January 9th, 2003, 05:53 PM
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.
galathaea
January 9th, 2003, 06:44 PM
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.
thpsthc
January 9th, 2003, 07:02 PM
Thanks; I will try both suggestions since they give me a good place to start.
thpsthc
January 9th, 2003, 07:15 PM
what's the link to the faq?
galathaea
January 9th, 2003, 07:57 PM
Here (http://www.codeguru.com/FAQS/#703)!
thpsthc
January 9th, 2003, 10:04 PM
thanks, I appreciate all the help!
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.