开发者

How to catch console-closing event?

The context of my problem is:

  1. I have a Windows .NET app (GUI) running as a main process.
  2. From this (parent) process, I create a couple of sub-processes as console processes.
  3. The main process sends data to the children processes 开发者_运维问答through named pipes.
  4. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜