C#单独启动进程的几种方式及使用特点(使用不当导致端口无法释放)

1、使用 System.Diagnostics.Process.Start(启动子进程,不等待子进程结束)

System.Diagnostics.Process.Start(@"C:\listfiles.bat");

2、使用Process (注意UseShellExecute的属性设置)

  Process serverProcess = new Process();
                serverProcess.StartInfo = new ProcessStartInfo(fileName);
                serverProcess.StartInfo.Arguments = "1";
                //特别注意 
                //UseShellExecute =false 表示重定向标准输入/输出/错误(可以理解为需求等待子进程的结束返回)
                //UseShellExecute =true  重定向标准输入/输出/错误(也就是不需要等待子进程的结束返回)
                serverProcess.StartInfo.UseShellExecute = true;
                serverProcess.Start();

  

posted @ 2020-04-10 21:57  月光流云  阅读(892)  评论(0编辑  收藏  举报