|
-
January 9th, 2003, 05:25 PM
#1
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.
-
January 9th, 2003, 05:44 PM
#2
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
-
January 9th, 2003, 06:53 PM
#3
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.
-
January 9th, 2003, 07:44 PM
#4
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
-
January 9th, 2003, 08:02 PM
#5
Thanks; I will try both suggestions since they give me a good place to start.
-
January 9th, 2003, 08:15 PM
#6
what's the link to the faq?
-
January 9th, 2003, 08:57 PM
#7
*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/
"It's hard to believe in something you don't understand." -- the sidhi X-files episode
galathaea: prankster, fablist, magician, liar
-
January 9th, 2003, 11:04 PM
#8
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|