How to scroll around unrequited programs in windows?

I am creating an application that monitors a selected group of programs and reloads them if necessary. With this group of programs, if something “went wrong” (that is, they must be restarted), the program will appear in the task manager as “not responding”.

Is there any way to iterate over non-responsive programs on Windows using api? Or, alternatively, I have a process identifier or a window handle, I can ask if it is responsive or not?

+3
source share
3 answers

First you must iterate over all the top-level windows. Do this by calling Win32 EnumWindows. This function requires a callback procedure, so it is bypassed for explanation in C #. In any case, check the documentation.

Then, at each iteration, call the function below, skipping the window handle:

[DllExport("user32.dll")]
static bool IsHungAppWindow(IntPtr theWndHandle);

A call to this function in a window should return true for a non-repeating window. Then get the process id by calling GetWindowThreadProcessId.

Then get a link to the process and exit it:

Process aPrc = Process.GetProcessById(aPrcID);
aPrc.Kill();
+4
source

I think this one is what you need.

Repeat the valid comment, for example:

Process[] processes = Process.GetProcessesByName("your process name");
if(!processes[0].Responding)
 // kill it or do something
+4
source

, , . , API , .

+2

Source: https://habr.com/ru/post/1733887/


All Articles