EDN Admin
Well-known member
Hi,
If I run a console program from Win 7 command prompt, the program runs in ~8 seconds.
If I use Process and/or ProcessStartInfo to run that same program from within a C# application, the program runs 5 times slower.
Heres the code. I have also tried this without the redirects and without processing any data received, and there is no improvement. The console program still runs 5 times slower than when executed directly from the command prompt. Setting
ProcessPriorityClass to AboveNormal makes no difference, which makes me think there is some other very fundamental issue.
Edit: The program being called generates approximately 100 lines of output, each line being about 20 characters long.
<pre class="prettyprint" style=" processStartInfo.FileName = cmd.ToString();
processStartInfo.Arguments = arguments.ToString();
processStartInfo.WorkingDirectory = Environment.CurrentDirectory;
processStartInfo.CreateNoWindow = true;
processStartInfo.RedirectStandardOutput = true;
processStartInfo.RedirectStandardError = true;
//processStartInfo.RedirectStandardInput = true;
processStartInfo.UseShellExecute = false;
//proc.EnableRaisingEvents = true;
// Start the process, then asynchronously read the output.
// Wait for process to exit.
// Cancel reading the output.
//
proc.StartInfo = processStartInfo;
started = proc.Start();
if (started)
{
//proc.PriorityClass = ProcessPriorityClass.AboveNormal;
proc.OutputDataReceived += ((sender, e) =>
{
outSb.Append(e.Data);
});
proc.BeginOutputReadLine();
proc.WaitForExit();
}[/code]
Ive seen a couple similar threads here and elsewhere, but without resolution.
Steve
<br/>
View the full article
If I run a console program from Win 7 command prompt, the program runs in ~8 seconds.
If I use Process and/or ProcessStartInfo to run that same program from within a C# application, the program runs 5 times slower.
Heres the code. I have also tried this without the redirects and without processing any data received, and there is no improvement. The console program still runs 5 times slower than when executed directly from the command prompt. Setting
ProcessPriorityClass to AboveNormal makes no difference, which makes me think there is some other very fundamental issue.
Edit: The program being called generates approximately 100 lines of output, each line being about 20 characters long.
<pre class="prettyprint" style=" processStartInfo.FileName = cmd.ToString();
processStartInfo.Arguments = arguments.ToString();
processStartInfo.WorkingDirectory = Environment.CurrentDirectory;
processStartInfo.CreateNoWindow = true;
processStartInfo.RedirectStandardOutput = true;
processStartInfo.RedirectStandardError = true;
//processStartInfo.RedirectStandardInput = true;
processStartInfo.UseShellExecute = false;
//proc.EnableRaisingEvents = true;
// Start the process, then asynchronously read the output.
// Wait for process to exit.
// Cancel reading the output.
//
proc.StartInfo = processStartInfo;
started = proc.Start();
if (started)
{
//proc.PriorityClass = ProcessPriorityClass.AboveNormal;
proc.OutputDataReceived += ((sender, e) =>
{
outSb.Append(e.Data);
});
proc.BeginOutputReadLine();
proc.WaitForExit();
}[/code]
Ive seen a couple similar threads here and elsewhere, but without resolution.
Steve
<br/>
View the full article