[英]What is the difference between the below processes?
此过程从我的应用程序“独立”运行。 我可以在脚本运行的同时使用我的表单,而不是等待退出。
string strCmdText = "some command line script";
System.Diagnostics.Process.Start("CMD.exe", strCmdText);
这个虽然在我的表单中停止进程,直到命令行窗口关闭:
Process p = new Process();
p.StartInfo.Verb = "runas";
p.StartInfo.FileName = cmd.exe;
p.Start();
对我来说,两者似乎都是相同的process.start()
。 那么区别是什么呢?
它们非常相似但不相同。
以下是Process.Start
方法的 实现 方法 ;
public static Process Start(string fileName, string arguments)
{
return Start(new ProcessStartInfo(fileName, arguments));
}
new ProcessStartInfo(fileName, arguments)
构造函数将第二个参数设置为参数字符串,即ProcessStartInfo.Arguments
属性而不是Verb
属性。 并且;
public static Process Start(ProcessStartInfo startInfo)
{
Process process = new Process();
if (startInfo == null) throw new ArgumentNullException("startInfo");
process.StartInfo = startInfo;
if (process.Start()) {
return process;
}
return null;
}
正如你从文档中看到的那样;
重载将资源与新的
Process
组件相关联。 如果该进程已在运行,则不会启动其他进程。 相反,重用现有流程资源,不会创建新的Process
组件。 在这种情况下,Start
不会返回新的Process
组件,而是向调用过程返回null
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.