I'm pretty much very new at C# and windows forms programming. I'm trying to build a very very simple form. I have only one button and a text box , When i click the button a process start at the background ( it's a process that i programmed in Python and compile to EXE file) , it's very simple process ... just print number from 1 to 4 in a 2 sec delay between each number I want the output to be display at the text box in a real-time meaning the number 1 to 4 in a 2 sec delay. I looked online and search a lot but couldn't find anything to help me with that. i read this thread -->How can I redirect process output (console) to richtextbox? and tried to implement what written there with no luck Thanks a lot! This is my code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private StringBuilder sortOutput;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
String output="";
using (Process sortProcess = new Process())
{
sortProcess.StartInfo.FileName = @"c:/req/dist/ex/ex.exe";
sortProcess.StartInfo.CreateNoWindow = true;
sortProcess.StartInfo.UseShellExecute = false;
sortProcess.StartInfo.RedirectStandardOutput = true;
sortProcess.Start();
output = sortProcess.StandardOutput.ReadLine();
// sortProcess.WaitForExit();
while (!(sortProcess.HasExited))
{
richTextBox1.AppendText(output.ToString());
Application.DoEvents(); // This keeps your form responsive by processing events
}
}
//richTextBox1.AppendText(sortOutput.ToString());
}
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
//?????
}
}
}