views:

8

answers:

0

Hi all,

I'm working with a BackgroundWorker Process from Windows .NET C# application.

From the async method I call many instance of cmd.exe Process (foreach), and read from StandardOutput, but at the 3-times cycle the ReadToEnd() method throw Timeout Exception.

Here the code:

    StreamWriter sw = null;
DataTable dt2 = null;
StringBuilder result = null;
Process p = null;

for(DataRow dr in dt1.Rows)
{
    arrLine = new string[4];    //new row
    result = new StringBuilder();

    arrLine[0] = dr["ID"].ToString();
    arrLine[1] = dr["ChangeSet"].ToString();

    #region Initialize Process CMD
    p = new Process();
    ProcessStartInfo info = new ProcessStartInfo();
    info.FileName = "cmd.exe";
    info.CreateNoWindow = true;
    info.RedirectStandardInput = true;
    info.RedirectStandardOutput = true;
    info.RedirectStandardError = true;
    info.UseShellExecute = false;
    p.StartInfo = info;
    p.Start();
    sw = new StreamWriter(p.StandardInput.BaseStream);
    #endregion

    using (sw)
    {
        if (sw.BaseStream.CanWrite)
        {
            sw.WriteLine("cd " + this.path_WORKDIR);
            sw.WriteLine("tfpt getcs /changeset:" + arrLine[1]);
        }
    }

    string strError = p.StandardError.ReadToEnd();      // Read shell error output commmand (TIMEOUT)
    result.Append(p.StandardOutput.ReadToEnd());        // Read shell output commmand

    sw.Close();
    sw.Dispose();

    p.Close();
    p.Dispose();
} 

Timeout is on code line:

string strError = p.StandardError.ReadToEnd();

Can you help me?

Thanks!