开发者

Process.WaitForExit not waiting

I have the following code and t开发者_开发知识库he WaitForExit method is not waiting. It just runs the command and moves on to the next statement. The command is to unintall an application and the parms are for the uninstall command. The uninstall runs fine but I need the uninstall to finish before moving on...it's not blocking.

ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = commandName;
startInfo.Arguments = parms;
Process process = Process.Start(startInfo);
process.WaitForExit();


I strongly suspect that Andrey's comment is right - the process you're starting is exiting, but having started a new process itself.

The simple way to find that out is to print out process.Id before calling WaitForExit, and then try to find that process in task manager. I suspect you'll find it won't be there.

You may want to loop round, sleeping briefly while waiting for another indicator of the uninstall being finished - such as a particular file or registry entry being removed. Not ideal, but it may be the best you've got.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜