下面是一段代码,这段代码将两个文件合并以生成另一个文件。
我的问题是,如果我在start()之后使用waitforexit(),我的代码会花费相当长的时间。如何加快上述循环的速度?
foreach (string jpegfile in files)
{
string fileName = jpegfile + ".dcm";
string ConfigFile =GetFileNameWithoutExtension(jpegfile) + ".cfg";
string destFile = System.IO.Path.Combine(DirectoryPath, fileName);
string command = "/C " + batFileName + " -C " + patientConfigFile + " " + jpegfile + " " + destFile;
try
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.UseShellExecute = false;
// You can start any process, HelloWorld is a do-nothing example.
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.Arguments = command;
process.StartInfo.CreateNoWindow = true;
process.Start();
process.WaitForExit();
this.counter++;
// Report progress as a percentage of the total task.
int percentComplete =
(int)((float)this.counter / (float)form.sumofImages * 100);
if (percentComplete > highestPercentageReached)
{
highestPercentageReached = percentComplete;
worker.ReportProgress(percentComplete);
}
}
catch (Exception exp)
{
MessageBoxButtons buttons = MessageBoxButtons.OK;
DialogResult result;
result = MessageBox.Show("Batch File execution error " + exp, "Warning", buttons);
}
}
我的问题是,如果我在start()之后使用waitforexit(),我的代码会花费相当长的时间。如何加快上述循环的速度?