【发布时间】:2020-05-07 07:45:09
【问题描述】:
我是 C# 编程的新手,有一段代码我想在循环中多次运行命令行进程。我还想等待命令行过程完成,然后使用不同的参数再次运行它。我所做的是我在一个循环中定义了该过程,并且一切正常。但是,我也想在每次进程结束时更新 GUI 上的进度条,但最终 Process.WaitForExit() 挂起我的 GUI 并且它不会更新进度条。当 for 循环完成时,进度条会更新。请帮帮我,这是我一直在尝试做的。
ProcessStartInfo processInfox = new ProcessStartInfo();
processInfox.CreateNoWindow = false;
processInfox.UseShellExecute = false;
processInfox.FileName = programPath;
processInfox.CreateNoWindow = true;
int startFrames = Convert.ToInt16(txtStartFrame.Text);
int endFrames = Convert.ToInt16(txtEndFrame.Text);
for (int i = startFrames; i <= endFrames; i++)
{
progressBar1.Value = (i / endFrames) * 100;
iName = fileFrames + "_" + i + ".jpg";
oName = outFrames + "\\" + outFileName + "_processed_" + i + ".jpg" ;
processInfox.Arguments = "-i \"" + iName + "\"" + progArgs + " -o \"" + oName + "\"";
using (Process processFire = Process.Start(processInfox))
{
processFire.WaitForExit();
}
}
【问题讨论】:
标签: c# loops user-interface command-line process