I'm trying to determine if a process is still alive (at the moment I did check, I'm aware it can be closed right after I do the check) by calling WaitForSingleObject()
with a handle get from Process.MainWindowHandle
which works just fine with IsIconic()
but it return WAIT_FAILED
and GetLastError()
a ERROR_INVALID_HANDLE
UInt32 r = WaitForSingleObject(handle, 0);
if(r == WAIT_OBJECT_0)
{
MessageBox.Show("still running!");
}
if(r == WAIT_FAILED)
{
throw new Win32Exception(Marshal.GetLastWin32Error());
}