this code does not close cmd windows after kill: using System; using…
- User
this code does not close cmd windows after kill: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;
namespace MeetingLobyHandler { public partial class Main : Form { public Main() { InitializeComponent(); }
codepublic string Command = ""; public Process process = null; private void Main_Load(object sender, EventArgs e) { var lines = File.ReadAllLines("config.ini"); Command = lines[0].Split(':')[1]; timer_command.Interval = Convert.ToInt32(lines[1].Split(':')[1]); lbl_status.Text = "Server is Stop..."; lbl_status.ForeColor = Color.Red; btn_stop.Enabled = false; } private void timer_command_Tick(object sender, EventArgs e) { KillCommand(); RunCommand(); Console.WriteLine("dfcsdfd"); } public void RunCommand() { process = new Process(); ProcessStartInfo processStartInfo = new ProcessStartInfo { FileName = "cmd.exe", Arguments = "/C " + Command, RedirectStandardOutput = false, RedirectStandardError = false, UseShellExecute = false, CreateNoWindow = false }; process.StartInfo = processStartInfo; process.Start(); } public void KillCommand() { process.Kill(); process.Close(); process.Dispose(); process = null; } private void btn_start_Click(object sender, EventArgs e) { RunCommand(); timer_command.Enabled = true; timer_command.Start(); lbl_status.Text = "Server is Running..."; lbl_status.ForeColor = Color.Green; btn_start.Enabled = false; btn_stop.Enabled = true; } private void btn_stop_Click(object sender, EventArgs e) { KillCommand(); timer_command.Enabled = false; timer_command.Stop(); lbl_status.Text = "Server is Stop..."; lbl_status.ForeColor = Color.Red; btn_start.Enabled = true; btn_stop.Enabled = false; } } - Assistant
- User
i do not want hide command window. i want to close it in killcommand method
- Assistant