Waiting 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
- Associate an instance of a Process component to a process you want to start. For more information, see Starting Processes.
- Start the process by calling the Start method.
- Call the appropriate WaitForInputIdle method:
- WaitForInputIdle() - instructs the Process component to wait indefinitely for the associated process to enter an idle state.
- WaitForInputeIdle(Int32) - 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.
' Visual Basic Dim myProcess as New Process() myProcess.Start("Notepad.exe") myProcess.WaitForInputIdle() // C# Process myProcess; myProcess = Process.Start("Notepad"); myProcess.WaitForInputIdle();