Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# synchronous process starting

Tags:

c#

.net

windows

I'm attempting to start a process from a piece of code but I want the code to pause execution until the process finishes and exits. Currently I'm using the System.Diagnostics.Process.Start() class to start (specifically) an uninstaller program, and the code executing afterwards does rely on the installer uninstaller finishing before it resumes execution.

Here's the code.

using System.Diagnostics;

var procStIfo = new ProcessStartInfo("cmd", "/c " + variableContainingUninstallerPath);
procStIfo.RedirectStandardOutput = true;
procStIfo.UseShellExecute = false;
procStIfo.CreateNoWindow = true;

var proc = new Process();
proc.StartInfo = procStIfo;
proc.Start();
like image 279
tearman Avatar asked Oct 26 '09 17:10

tearman


1 Answers

After your Start() call, add:

proc.WaitForExit();

See Process.WaitForExit for details.

like image 121
Reed Copsey Avatar answered Nov 09 '22 20:11

Reed Copsey