Command to close an application of console?

后端 未结 6 443
天涯浪人
天涯浪人 2020-11-28 08:26

I need to close the console when the user selects a menu option.

I tried using close() but it did not work..

how can I do this?

6条回答
  •  情歌与酒
    2020-11-28 09:10

     //How to start another application from the current application
     Process runProg = new Process();
     runProg.StartInfo.FileName = pathToFile; //the path of the application
     runProg.StartInfo.Arguments = genArgs; //any arguments you want to pass
     runProg.StartInfo.CreateNoWindow = true;
     runProg.Start();
    
     //How to end the same application from the current application
     int IDstring = System.Convert.ToInt32(runProg.Id.ToString());
     Process tempProc = Process.GetProcessById(IDstring);
     tempProc.CloseMainWindow();
     tempProc.WaitForExit();
    

提交回复
热议问题