问题
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