Export (0) Print
Expand All

Determining If a Process Is Responding

You can use the Responding property to determine if the user interface of a process is responding. When you attempt to read the Responding property, a request is sent to the user interface of the target process. If there is an immediate response, the return property value is true; a false property value is returned if there is no response from the interface. This property is useful if you need to force a frozen application to close.

To determine if a process is responding

  1. If the process was not started with a component, associate a Process component to the target process. For more information, see Binding to Existing Processes.
  2. Read the Responding property by calling the Responding method.
  3. Determine a course of action to take depending on the property value.

The following example shows how to determine if Notepad is responding. If the Response property is true, call the CloseMainWindow method to close the application. If the Response property is false, the Kill method is called to force the process to close.

' Visual Basic
Dim myProcesses() as Process
myProcesses = Process.GetProcessesByName("Notepad.exe")
' Tests the Responding property for a True return value.
If myProcesses(0).Responding Then
   myProcesses(0).CloseMainWindow()
Else
   ' Forces the process to close if the Responding value is False.
   myProcesses(0).Kill()
End If

// C#
Process[] notepads;
notepads = Process.GetProcessesByName("Notepad.exe");
// Test to see if the process is responding.
if (notepads[0].Responding)
{
   notepads[0].CloseMainWindow();
}
else
{
   notepads[0].Kill();
}

See Also

Retrieving Information About Processes | Starting Processes | Managing Processes | Stopping Processes | Binding to Existing Processes

Show:
© 2014 Microsoft