I have some code like this:
process.CloseMainWindow();
if (!process.WaitForExit(5000)) { process.Kill(); }
The idea is to let the process exit gracefully, but if it takes longer than 5 seconds, I assume it needs to be killed.
This appears to work in most cases, but if the process has thrown up a windows error message, it just hangs. I previously had only the "process.Kill()" and that worked, so I have to assume it's actually getting stuck on the WaitForExit(5000) call, even though I'm giving it a timeout value.
Any reason this would happen?
EDIT: I'm wondering if maybe it's the CloseMainWindow() that's actually hanging, because of that error message. In which case, would checking the process's "responding" property before trying the CloseMainWindow() method actually return "false"? If so, I could check that and then use Kill if that's the case.