开发者

C# synchronous process starting

开发者 https://www.devze.com 2022-12-09 05:50 出处:网络
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

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 " + variableC开发者_开发问答ontainingUninstallerPath);
procStIfo.RedirectStandardOutput = true;
procStIfo.UseShellExecute = false;
procStIfo.CreateNoWindow = true;

var proc = new Process();
proc.StartInfo = procStIfo;
proc.Start();


After your Start() call, add:

proc.WaitForExit();

See Process.WaitForExit for details.

0

精彩评论

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