I know that title doesn't explain it well so I'll explain it better here. I'm working on a windows forms application (let it be app A) that essentially is GUI for another written in a different language command-line app (app B). The problem is that I don't know how to run multiple commands on a single instance of an application. I need to make pressing a button change some values with a single command executed on app B and pressing other button displays the values. It doesn't work because after pressing the first button the values change but when another button is pressed another instance of app B is called with displaying command and its values are unchanged (default).
private void button2_Click(object sender, EventArgs e) //apply command
{
using (Process process = new Process)
{
process.StartInfo.FileName = FileLocation;//app B location
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.Arguments = "apply " + textBox1.Text + "#";
process.Start();
//apply,# ->command for changing values
//textBox1.Text is input to specify how values are changed
StreamReader reader = process.StandardOutput;
string output = reader.ReadToEnd();
label1.Text = output;
process.WaitForExit();
}
}
private void button8_Click(object sender, EventArgs e) //view command
{
using (Process process = new process)
{
process.StartInfo.FileName = FileLocation;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.Arguments = "view";
process.Start();
//view -> command to see values
StreamReader reader = process.StandardOutput;
string output = reader.ReadToEnd();
label1.Text = output;
//process.WaitForExit();
}
}
I know that the problem is caused by methods using different process but I don't know how to make them use one using block