Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling external exe using cmd (System.Diagnostics) is slow on W2k3

Status
Not open for further replies.

nicsin

Programmer
Jul 31, 2003
743
0
0
GB
Hi all

I have a very weird problem. I developed the application on XP/IIS5 and everything was fine. When I deployed it on W2k3 server with IIS6 I started getting long delays.

The code below runs an exe using cmd and then reads the response back in a local variable. In W2k3 there is always a 13 second delay just before calling Peek() the first time. Subsequent peeks are ok.

I have concluded that the problem is not in the code as it executes without problems on XP, it is with the W2k3/IIS6 but I can't find the solution.

Code:
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = Environment.GetEnvironmentVariable("COMSPEC");
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.Arguments = command;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.ErrorDataReceived += new DataReceivedEventHandler(ErrorHandler);
if (proc.Start())
{
Logger.Log("VersionManager.Execute", "in start");
proc.BeginErrorReadLine();
StreamReader sr = proc.StandardOutput;
char[] c = null;
[b]//There is always 13 seconds here[/b]
while (sr.Peek() >= 0)
{
c = new char[5];
sr.Read(c, 0, c.Length);
string temp = new string(c);
ret += temp;
}
proc.WaitForExit(20000);
proc.Close();
proc.Dispose();

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top