Game Development Reference
In-Depth Information
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.Arguments = arguments;
process.StartInfo.CreateNoWindow = true;
process.Start();
StreamReader reader = process.StandardOutput;
while (!process.HasExited)
{
OuputField.Text += reader.ReadLine() + Environment.NewLine;
Application.DoEvents();
}
}
The last piece of important code is to be placed in the closing event of the Form
wrapping the console application. This code checks if the process is valid and if it
has not exited yet. If true , the process is aborted. Obviously, this event has to have
a reference to the process created by LaunchConsoleApplication .
The following code shows this event logic.
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
if (_process != null && !_process.HasExited)
{
_process.Kill();
}
}
Sample Usage
The example provided alongside the implementation for this chapter is very simple.
The demo console application is given two arguments: an iteration count and a
message to print. The message is printed out however many iterations are specified.
The following code in the Windows Forms demo makes the console application
print “Hello World” out five times. The number of iterations to print the message
out is dependent on the iteration count specified as a parameter to the launch
method.
Search Nedrilad ::




Custom Search