I am trying to find out if a process is not frozen by sending a message to its handler and see if it reaches it. I caot use Process.Responding because it looks like the monitored application needs to have a window. This has to work for processes that run without a window. I use this method but it always retus FALSE:
Const SMTO_BLOCK = &H1
Const SMTO_ABORTIFHUNG = &H2
Const WM_NULL = &H0
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
Public Function SendMessageTimeout(hWnd As HandleRef, msg As Integer, wParam As IntPtr, lParam As IntPtr, flags As Integer, timeout As Integer, ByRef pdwResult As IntPtr) As IntPtr
End Function
Public Function ProcessIsResponding(ByVal proc As Process) As Boolean
Dim handleRef As HandleRef = New HandleRef(proc, proc.Handle)
Dim timeout As Integer = 10000
Dim lpdwResult As IntPtr
Dim lResult As IntPtr = SendMessageTimeout(handleRef, WM_NULL, IntPtr.Zero, IntPtr.Zero, SMTO_ABORTIFHUNG And SMTO_BLOCK, timeout, lpdwResult)
Retu lResult <> IntPtr.Zero
End Function
This works if I replace proc.Handle by proc.MainWindowHandle but I guess in this case a window handle is needed. What happens if there's no window? What other choice do I have?
