I have a c# program and currently I run 2 windows, the first one is form window and and the second one is console window for debugging.
The console window created accoeding the following:
Create a Windows Form project... Then: Project Properties -> Application -> Output Type -> Console Application
How can I close the console window from the form by button click?
Edit:
I tried to do the following but this is close the form window only..
private void button1_Click(object sender, EventArgs e)
{
System.Environment.Exit(0);
}
Edit 2: the previous code works only before the following code performed.
using (process = new Process())
{
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
process.StartInfo.WorkingDirectory = @"C:\";
process.StartInfo.FileName = Path.Combine(Environment.SystemDirectory, "cmd.exe");
// Redirects the standard input so that commands can be sent to the shell.
process.StartInfo.RedirectStandardInput = true;
// Runs the specified command and exits the shell immediately.
//process.StartInfo.Arguments = @"/c ""dir""";
process.OutputDataReceived += ProcessOutputDataHandler;
process.ErrorDataReceived += ProcessErrorDataHandler;
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
// Send a directory command and an exit command to the shell
process.StandardInput.WriteLine("cd " + currentPath);
process.StandardInput.WriteLine("ibt -mic");
}