Share via


How to: Wait for Processes to Complete Actions 

A process is said to be idle when its main window is waiting for input from the system. In order to test the process for its idle state, you must first bind a Process component to it. You can call the WaitForInputIdle method before having the target process perform an action.

The WaitForInputIdle method instructs a Process component to wait for the associated process to enter an idle state. The method is useful, for example, when your application waits for a process to finish creating its main window before communicating with that window. The WaitForInputIdle method only works with processes that have a user interface.

To wait for a process to complete an action

  1. Associate an instance of a Process component to a process you want to start. For more information, see How to: Specify Processes.

  2. Start the process by calling the Start method.

  3. Call the appropriate WaitForInputIdle method:

    • WaitForInputIdle — instructs the Process component to wait indefinitely for the associated process to enter an idle state.

    • WaitForInputIdle — instructs the Process component to wait the specified number of milliseconds for an associated process to enter an idle state.

    The following example shows how to call the WaitForInputIdle method to wait for Notepad to complete loading before assigning its modules property to an empty array.

    Dim myProcess As New Process()
    myProcess = Process.Start("Notepad.exe")
    myProcess.WaitForInputIdle()
    
    Process myProcess;
    myProcess = Process.Start("Notepad");
    myProcess.WaitForInputIdle();
    
    Process myProcess;
    myProcess = Process.Start("Notepad");
    myProcess.WaitForInputIdle();
    

See Also

Tasks

How to: Bind to Existing Processes
How to: Specify Processes
How to: Stop Processes

Concepts

Introduction to Monitoring and Managing Windows Processes