While I can do this:
System.Diagnostics.Process.Start(@"C:\MyFolder\MyProgram.cmd");
I can't do this:
var process = new System.Diagnostics.Process();
process.Start(@"C:\MyFolder\MyProgram.cmd");
Error: Member 'System.Diagnostics.Process.Start(string)' cannot be accessed with an instance reference; qualify it with a type name instead.
What is the reason behind this? Can anyone please explain?
Thanks in advance!
All the parametered overloads of Process.Start are static. If you want to use the second syntax then you have to set instance state first which is just the "filename" property of StartInfo:
var proc = new Process();
proc.StartInfo.FileName = @"C:\MyFolder\MyProgram.cmd";
proc.Start();
Note that this should be equivalent to System.Diagnostics.Process.Start(@"C:\MyFolder\MyProgram.cmd"); because as the MSDN says: "The overload is an alternative to the explicit steps of creating a new Process instance, setting the FileName member of the StartInfo property, and calling Start for the Process instance."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With