How to check if process is not responding?

There is no general solution to this problem.

It is impossible to tell if a particular process is hanging or not, because the term “hanging” is entirely dependent upon the context of the process that is executing.

The hanging process will always do what it was coded to do. The developer may have coded it badly, but Windows can’t make assumptions about what is right/wrong.

Possible ideas to try might be:

  1. The Process.Responding call will indicate whether or not a process that is executing a windows message loop is responding.

  2. One possible solution for the more general case might be to poll the memory usage for the process at intervals and if it doesn’t change after enough time, assume that it is hung. You could do this with Process.WorkingSet64. However, I expect that this would cause a number of false positives – stable processes that are not processing anything might appear to be hanging. It would also cause false negatives where a hanging process that had a memory leak would appear to be doing something useful, when in fact it was stuck in a loop.

  3. If the process writes to the StandardError/StandardOutput streams (as many console applications do), then you could try listening for such output: Process.BeginOutputReadLine and Process.BeginErrorReadLine. If there is no such output within a given period, you might deduce that it has hung.

But you’re not going to find anything that works in the general case.

Leave a Comment