WaitForExit
method call is the one that is telling main thread to wait till the process is exited. You can remove it, if possible, to keep UI thread active.
Asynchronously reading output:
private void button1_Click(object sender, EventArgs e)
{
using (Process process = new Process())
{
process.StartInfo.FileName = "Executable Location Here";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardInput = true;
process.EnableRaisingEvents = true;
process.Exited += process_Exited;
process.OutputDataReceived += ProccesOutputDataReceived;
process.ErrorDataReceived += ProccesErrorDataReceived;
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
}
}
void process_Exited(object sender, EventArgs e)
{
}
void ProccesErrorDataReceived(object sender, DataReceivedEventArgs e)
{
}
void ProccesOutputDataReceived(object sender, DataReceivedEventArgs e)
{
}
Code above may need modifications for complex situations involving multiple threads, quick processing in called process and other overheads.