How to: Determine 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
If the process was not started with a component, associate a Process component to the target process. For more information, see How to: Bind to Existing Processes.
Read the Responding property.
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 Responding property is true, call the CloseMainWindow method to close the application. If the Responding property is false , the M:System.Diagnostics.Process.Kill method is called to force the process to close.
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
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
Tasks
How to: Bind to Existing Processes