Process waitForExit() doesn't work

亡梦爱人 提交于 2019-12-25 18:19:15

问题


I have the following code:

Process p = new Process();
p.StartInfo.FileName = Path.GetDirectoryName(Application.ExecutablePath) + "\\unRAR.exe";



p.StartInfo.Arguments = @"e c:\appData.rar c:\folderek\";

p.Start();
p.WaitForExit(9000);

I would like the window not to close after extracting files (unRAR.exe extracts them). WaitForExit(9000) seems not to work. I read dozens of sites and still can't find any solution.


回答1:


http://msdn.microsoft.com/en-us/library/fb4aw7b8.aspx reading this article tells you that the WaitForExit() does not keep the program alive, it just waits for the associated program to exit. If the associated program(unzip.exe here) exits, you will not be able to stop the unzip.exe program from exiting.




回答2:


Process.WaitForExit makes your application wait for the other process to exit. It has no impact at all on the started process itself.




回答3:


Try to create bat file and insert there command to wait (using command timeout or other solution from thread Sleeping in a batch file

And start in Process yours bat file



来源:https://stackoverflow.com/questions/14688239/process-waitforexit-doesnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!