G
Gidi
Hi,
I'm trying to run a process and catch it's output and display it in a
richTextBox.
the process I'm running, runs some other processes, I'm using Thread to run
this process, my problem is, that in the stage that the new process starts,
there is no output, and the thread "thinks" the process is over and finishes.
if i'm not using theards, it's works fine, but then i can't write the output
to my RichTextBox.
can some one help me?
here is some of my code:
private void ReadStdOutputThreadProc()
{
while (!c_Process.HasExited)
{
try
{
string str = c_StreamOutput.ReadLine();
while (!c_StreamOutput.EndOfStream)
{
c_StreamOutput.BaseStream.Flush();
Thread.Sleep(100);
if (str != null && str != String.Empty)
{
richTextBox1.Invoke((MethodInvoker)delegate {
richTextBox1.Text += Environment.NewLine + str; });
}
str = c_StreamOutput.ReadLine();
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
}
I'm trying to run a process and catch it's output and display it in a
richTextBox.
the process I'm running, runs some other processes, I'm using Thread to run
this process, my problem is, that in the stage that the new process starts,
there is no output, and the thread "thinks" the process is over and finishes.
if i'm not using theards, it's works fine, but then i can't write the output
to my RichTextBox.
can some one help me?
here is some of my code:
private void ReadStdOutputThreadProc()
{
while (!c_Process.HasExited)
{
try
{
string str = c_StreamOutput.ReadLine();
while (!c_StreamOutput.EndOfStream)
{
c_StreamOutput.BaseStream.Flush();
Thread.Sleep(100);
if (str != null && str != String.Empty)
{
richTextBox1.Invoke((MethodInvoker)delegate {
richTextBox1.Text += Environment.NewLine + str; });
}
str = c_StreamOutput.ReadLine();
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
}