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();
source
share