我试图通过向其处理程序发送消息并查看是否到达它来查明进程是否未被冻结。
我无法使用Process.Responding
,因为它看起来像受监控的应用程序需要有一个窗口。这必须适用于没有窗口的进程。我使用此方法,但它总是返回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)
Return lResult <> IntPtr.Zero
End Function
如果我用proc.Handle
替换proc.MainWindowHandle
,这是有效的,但我想在这种情况下需要一个窗口句柄。如果没有窗户会怎么样?我还有其他选择吗?