The context of my problem is:
- I have a Windows .NET app (GUI) running as a main process.
- From this (parent) process, I create a couple of sub-processes as console processes.
- The main process sends data to the children processes 开发者_运维问答through named pipes.
- In the main app, I have a list of the sub-processes.
My probleme is that each console has a close ("x") button and can be terminated (whatever the way it is). Since I keep a list of the created consoles in my main app, I would like to know when a console is killed or exited.
My console (child process) program is simply a "main()" with a loop function that reads the pipe (and displays the data). It has no message system or whatever else that could handle a windowing "exit".
The first idea that comes to my head is to poll the sub-processes from the main app to refresh the list. But this means I have to introduce a timer or a thread that watches the consoles. I don't like the idea.
Does someone have a better idea?
WaitForSingleObject(hThread, 0)
will tell you whether the thread specified in hThread
argument is signaled and therefore finished. Same goes to hProcess
.
Both handles of your child process are returned after CreateProcess()
call. You can either close them immediately, or monitor using WaitForSingleObject
.
精彩评论