Reputation: 1434
This process is running "independently" from my app. I can use my form meanwhile the script is running, not waiting for exit.
string strCmdText = "some command line script";
System.Diagnostics.Process.Start("CMD.exe", strCmdText);
This one though stops the process in my form till command line window is being closed:
Process p = new Process();
p.StartInfo.Verb = "runas";
p.StartInfo.FileName = cmd.exe;
p.Start();
To me both seems to be the same process.start()
. So what is the difference?
Upvotes: 3
Views: 386
Reputation: 98848
They are very similar but not equivalent.
Here is how Process.Start
method implemented;
public static Process Start(string fileName, string arguments)
{
return Start(new ProcessStartInfo(fileName, arguments));
}
new ProcessStartInfo(fileName, arguments)
constructor sets second parameter to arguments string which is ProcessStartInfo.Arguments
property not Verb
property. And also;
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;
}
As you can see from it's documentation;
The overload associates the resource with a new
Process
component. If the process is already running, no additional process is started. Instead, the existing process resource is reused and no newProcess
component is created. In such a case, instead of returning a newProcess
component,Start
returnsnull
to the calling procedure.
Upvotes: 2