WaitForInputIdle 的注意细节

  MSDN上如此说:
  The WaitForInputIdle function waits until the specified process is waiting for user input with no input pending, or until the time-out interval has elapsed.
  DWORD WaitForInputIdle( HANDLE hProcess, // handle to process
         DWORD dwMilliseconds // time-out interval
      );

  Parameters
hProcess
  
[in] Handle to the process. If this process is a console application or does not have a message queue, WaitForInputIdle returns immediately.
dwMilliseconds
  
[in] Specifies the time-out interval, in milliseconds. If dwMilliseconds is INFINITE, the function does not return until the process is idle.

  Return Values
  The following table shows the possible return values:

ValueMeaning
0The wait was satisfied successfully.
WAIT_TIMEOUTThe wait was terminated because the time-out interval elapsed.
-1An error occurred. To get extended error information, use the GetLastError function.

  Remarks

  The WaitForInputIdle function enables a thread to suspend its execution until the specified process has finished its initialization and is waiting for user input with no input pending. This can be useful for synchronizing a parent process and a newly created child process. When a parent process creates a child process, the CreateProcess function returns without waiting for the child process to finish its initialization. Before trying to communicate with the child process, the parent process can use WaitForInputIdle to determine when the child's initialization has been completed. For example, the parent process should use WaitForInputIdle before trying to find a window associated with the child process.

The WaitForInputIdle function can be used at any time, not just during application startup.

Requirements

Windows NT/2000: Requires Windows NT 3.1 or later.
Windows 95/98: Requires Windows 95 or later.
Header: Declared in Winuser.h; include Windows.h.
Library: Use User32.lib.

 

  补充:我觉得WaitForInputIdle这个函数在CreateProcess之后只是为新进程初始化进程代码然后就返回,并不是等进程完全创建好在返回。这一点大家可以用有界面的程序来测试,因为有界面的程序在代码初始化完成之后还要做一些其他事情然后再显示出界面的,所以创建有界面的程序显示界面是WaitForInputIdle已经返回了。如有不对,请指教。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值