简体   繁体   English

使用spawnl并等待子进程退出

[英]using spawnl and waiting for child process to exit

I am using c++ in borland development studio to launch a process. 我在borland Development Studio中使用c ++启动过程。 After the process is launched, the parent application is supposed to wait for it, but still keep processing windows messages. 启动该过程后,父应用程序应该等待它,但仍继续处理Windows消息。

I tried using spawnl with P_WAIT after launching a timer, but timer wont fire when thread is blocked, i also tried using spawnl with P_NOWAIT together with cwait, but that didnt work either. 我在启动计时器后尝试将spawnl与P_WAIT一起使用,但是当线程被阻塞时,计时器不会触发,我也尝试将spawnl与P_NOWAIT和cwait一起使用,但是那也不起作用。

any suggestions ? 有什么建议么 ?

many thanks 非常感谢

Are you waiting for the process to complete in a method that handles Windows messages? 您是否正在等待处理Windows消息的方法中的完成过程? If you wait for the new process in a button-click handler, Windows won't process any more messages until the button-click method completes. 如果您在按钮单击处理程序中等待新的过程,则在按钮单击方法完成之前,Windows将不再处理任何消息。

If you need timer-based background processing you have a few options: 如果您需要基于计时器的后台处理,则有以下几种选择:

  1. Create a thread to wait for the process to complete. 创建一个线程以等待该过程完成。
  2. Create a new timer that checks periodically with WaitForExit() to determine when the other process completes. 创建一个新的计时器,该计时器定期使用WaitForExit()检查以确定其他进程何时完成。
  3. In your current handler, call Windows WaitForExit() using your timer period as the argument. 在当前的处理程序中,使用计时器时间段作为参数调用Windows WaitForExit()。 If the process isn't complete when WaitForExit() returns, do the timer-based processing. 如果在WaitForExit()返回时该过程未完成,请执行基于计时器的处理。 Note that this option still results in no Windows messages being processed. 请注意,此选项仍然不会处理任何Windows消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM