Is there any possibility to check from code if another process is not responding?
The problem is even if the app is crashed and on the Manager's list is marked as 'Not Responding', the Process.Responding property is still returning 'true'.
The 'Exited' event and function 'WaitForExit' are do any action if the process is- what is clear- exited. So it's not the point.
Problem in two words; I need to know that the application is crashed. How to check it from the code?
Thank you for your time.
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:
The Process.Responding call will indicate whether or not a process that is executing a windows message loop is responding.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With