Redirecting all console messages to textbox

214 views Asked by At

First of all, sorry for the bad grammar and poor English

I'm working on a C# winforms project which simplifies the arguments for another cmd based program. I am using process redirect methods, and it kind of works great and all, but... after around 10 seconds it lags and only outputs the result to the textbox every 15-20 seconds. I was wondering if there is a way to "flush" the streams buffer.

So far this is some of the code I have (only code that handles the cmd anyhow):

Process cmdHorch = new Process()
{
    StartInfo = new ProcessStartInfo()
    {
        FileName = baseDir + "donich.exe",
        Arguments = startstring,
        CreateNoWindow = true,
        UseShellExecute = false,
        ErrorDialog = false,
        RedirectStandardInput = true,
        RedirectStandardOutput = true,
        RedirectStandardError = true,
    },
    EnableRaisingEvents = true,
    SynchronizingObject = this
};
cmdHorch.OutputDataReceived += (s, ea) => this.findLine.AppendText(ea.Data + Environment.NewLine);

cmdHorch.Start();
cmdHorch.BeginOutputReadLine();

I've tried puzzling around with "cmdHorch.StandardOutput.BaseStream.Flush();" in order to force flush the stream but it failed miserably.. I have searched for a couple of days without any luck regarding this buffer issue.

EDIT: if I run donich.exe with the same parameters as I put into this program it outputs every (at the longest) 2 seconds (a string of minimum of 30 chars)

EDIT (2/1-2015) the donich.exe spits out about 1600 lines to the console(or redirected to the textbox) the first second it runs.

0

There are 0 answers