2

I have the following code and the 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();
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
Bayrat
  • 161
  • 1
  • 3
  • 17

1 Answers1

9

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.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194