WaitForInputIdle function (Windows)

Switch View :
ScriptFree
WaitForInputIdle function

Applies to: desktop apps only

Waits until the specified process has finished processing its initial input and is waiting for user input with no input pending, or until the time-out interval has elapsed.

Syntax

DWORD WINAPI WaitForInputIdle(
  __in  HANDLE hProcess,
  __in  DWORD dwMilliseconds
);

Parameters

hProcess [in]

A handle to the process. If this process is a console application or does not have a message queue, WaitForInputIdle returns immediately.

dwMilliseconds [in]

The time-out interval, in milliseconds. If dwMilliseconds is INFINITE, the function does not return until the process is idle.

Return value

The following table shows the possible return values for this function.

Return code/valueDescription
0

The wait was satisfied successfully.

WAIT_TIMEOUT

The wait was terminated because the time-out interval elapsed.

WAIT_FAILED

An error occurred.

 

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. If the process has multiple threads, the WaitForInputIdle function returns as soon as any thread becomes idle.

WaitForInputIdle can be used at any time, not just during application startup. However, WaitForInputIdle waits only once for a process to become idle; subsequent WaitForInputIdle calls return immediately, whether the process is idle or busy.

WaitForInputIdle 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 the WaitForInputIdle function to determine when the child's initialization has been completed. For example, the parent process should use the WaitForInputIdle function before trying to find a window associated with the child process.

Requirements

Minimum supported client

Windows XP

Minimum supported server

Windows Server 2003

Header

Winuser.h (include Windows.h)

Library

User32.lib

DLL

User32.dll

See also

CreateProcess
Process and Thread Functions
Synchronizing Execution of Multiple Threads

 

 

Send comments about this topic to Microsoft

Build date: 3/7/2012

Community Content


dmex
C# syntax
[DllImport("user32.dll", CharSet=CharSet.Auto, SetLastError=true)]
internal static extern int WaitForInputIdle(IntPtr hProcess, int dwMilliseconds);

dmex
vb.net syntax
<DllImport("user32.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
Public Shared Function WaitForInputIdle(ByVal hProcess As IntPtr, ByVal dwMilliseconds As Integer) As Integer
End Function

JizzleB
.NET users should use Process.WaitForInputIdle

.NET Framework users should look at using Process.WaitForInputIdle which is the managed equivalent of this function