c# - System.Diagnostics.Process WaitForExit doesnt kill the process on timeout -




i run 7-zip c# code:

processstartinfo processstartinfo = new processstartinfo {     windowstyle = processwindowstyle.hidden,     filename = zipfileexepath,     arguments = "x \"" + zippath + "\" -o\"" + extractpath + "\"" };  using (process process = process.start(processstartinfo)) {     if (process.waitforexit(timeout))     {     }     else     {         s_logger.errorformat("timeout whilte extracting extracting {0}", zippath);     }      process.close(); } 

now see happening when timeout hits, still 7-zip process exists in task manager. why happening? put both close , dispose

your question mentions 3 methods on process class:

none of methods process, not kill it.

waitforexit observational method, wait , see if process terminates itself. overload timeout return bool telling whether method observed process terminated or not. if didn't, it's presumably still running.

close , dispose nothing or process running, merely closes handle have internally in process class mechanism how class can keep tabs of process in question.

it's idea close handle when you're done observing running process.

however, if want process terminate, have call process.kill.





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -

python - Read npy file directly from S3 StreamingBody -