
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
448
|
Chapter 8: Diagnostics
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), or that response cannot be determined for this
process as there is no main window handle (
Unknown)...
The
Responding property always returns true if the process in question does not have
a
MainWindowHandle. Processes such as Idle, spoolsv, Rundll32, and svchost do not
have a main window handle and therefore the
Responding property always returns
true for them. To weed out these processes, you can use the MainWindowHandle prop-
erty of the
Process class, which returns the handle of the main window for a process.
If this property returns zero, the process has no main window.
To determine whether all processes on a machine are responding, you can call the
IsProcessResponding method as follows:
MyObject.ProcessRespondingState state;
foreach (Process proc in Process.GetProcesses( ))
Trace.WriteLine("{0} does not have a MainWindowHandle",
process.ProcessName);
return ProcessRespondingState.Unknown; ...