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();
浙公网安备 33010602011771号