8.2. Determining Whether a Process Has Stopped Responding
Problem
Youneed to watch one or more processes to determine whether the user interface has stopped responding to the system. This functionality is similar to the column in the TaskManager that displays the text Responding or Not Responding, depending on the state of the application.
Solution
Use the method and enumeration shown in Recipe 8.2 to determine whether a process has stopped responding.
Example 8-1. Determining whether a process has stopped responding
public static ProcessRespondingState IsProcessResponding(Process process)
{
if (process.MainWindowHandle == IntPtr.Zero)
{
Trace.WriteLine("{0} does not have a MainWindowHandle",
process.ProcessName);
return ProcessRespondingState.Unknown;
}
else
{
// This process has a MainWindowHandle.
if (!process.Responding)
}
Trace.WriteLine("{0} is not responding.",process.ProcessName);
return ProcessRespondingState.NotResponding;
}
else
{
Trace.WriteLine("{0} is responding.",process.ProcessName);
return ProcessRespondingState.Responding;
}
}
}
public enum ProcessRespondingState
{
Responding,
NotResponding,
Unknown
}Discussion
The IsProcessResponding method accepts a single parameter, process, identifying a process. The Responding property is then called on the Process object represented by the process parameter. This property returns a ProcessRespondingState enumeration value to indicate that a process is currently responding (Responding), that it is not currently responding (NotResponding ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access